当前位置: 首页>>代码示例>>C#>>正文


C# Context.SendBroadcast方法代码示例

本文整理汇总了C#中Android.Content.Context.SendBroadcast方法的典型用法代码示例。如果您正苦于以下问题:C# Context.SendBroadcast方法的具体用法?C# Context.SendBroadcast怎么用?C# Context.SendBroadcast使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Android.Content.Context的用法示例。


在下文中一共展示了Context.SendBroadcast方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: SendBroadcastForToastMessage

 public static void SendBroadcastForToastMessage(Context context, string messageToToast)
 {
     var toastIntent = new Intent(AppConstants.APPLICATION_COMMAND);
     toastIntent.PutExtra(AppConstants.COMMAND_TYPE_ID, (int)AppConstants.ApplicationCommandType.ShowToastMessage);
     toastIntent.PutExtra(AppConstants.TOAST_MESSAGE_KEY, messageToToast);
     context.SendBroadcast(toastIntent);
 }
开发者ID:talalbutt,项目名称:monodroid-locationservice-bootstrap,代码行数:7,代码来源:NotificationHelper.cs

示例2: AddFileToGallery

 public static void AddFileToGallery(Context context, string filePath)
 {
     Intent mediaScanIntent = new Intent(Intent.ActionMediaScannerScanFile);
     File file = new File(filePath);
     var contentUri = Uri.FromFile(file);
     mediaScanIntent.SetData(contentUri);
     context.SendBroadcast(mediaScanIntent);
 }
开发者ID:es-repo,项目名称:wlpgnr,代码行数:8,代码来源:IntentShortcuts.cs

示例3: OnReceive

        public override void OnReceive(Context context, Intent intent)
        {
            //There's no point in going any further if the service isn't running.
            if (!App.Current.AudioServiceConnection.IsPlayerBound) return;

            //Aaaaand there's no point in continuing if the intent doesn't contain info about headset control inputs.
            var intentAction = intent.Action;
            if (!Intent.ActionMediaButton.Equals(intentAction))
            {
                return;
            }

            var keyEvent = (KeyEvent) intent.GetParcelableExtra(Intent.ExtraKeyEvent);
            if (keyEvent.Action != KeyEventActions.Down) return;

            var keycode = keyEvent.KeyCode;

            //Switch through each event and perform the appropriate action based on the intent that's ben
            if (keycode == Keycode.MediaPlayPause || keycode == Keycode.Headsethook)
            {
                //Toggle play/pause.
                var playPauseIntent = new Intent();
                playPauseIntent.SetAction(AudioPlaybackService.PlayPauseAction);
                context.SendBroadcast(playPauseIntent);
            }

            if (keycode == Keycode.MediaNext)
            {
                //Fire a broadcast that skips to the next track.
                var nextIntent = new Intent();
                nextIntent.SetAction(AudioPlaybackService.NextAction);
                context.SendBroadcast(nextIntent);
            }

            if (keycode == Keycode.MediaPrevious)
            {
                //Fire a broadcast that goes back to the previous track.
                var previousIntent = new Intent();
                previousIntent.SetAction(AudioPlaybackService.PrevAction);
                context.SendBroadcast(previousIntent);
            }
        }
开发者ID:jayharry28,项目名称:Audiotica,代码行数:42,代码来源:HeadsetButtonsReceiver.cs

示例4: RefreshWidget

		/**
     * Sends a request to the rich push message to refresh with a delay
     * @param context Application context
     * @param delayInMs Delay to wait in milliseconds before sending the request
     */
		public static void RefreshWidget(Context context, long delayInMs) {
			Intent refreshIntent = new Intent(context, typeof (RichPushWidgetProvider));
			refreshIntent.SetAction (RichPushWidgetProvider.REFRESH_ACTION);

			if (delayInMs > 0) {
				PendingIntent pendingIntent = PendingIntent.GetBroadcast(context, 0, refreshIntent, 0);
				AlarmManager am = (AlarmManager) context.GetSystemService(Context.AlarmService);
				am.Set (AlarmType.RtcWakeup, (long) new TimeSpan (DateTime.Now.Ticks).TotalMilliseconds + delayInMs, pendingIntent);
			} else {
				context.SendBroadcast(refreshIntent);
			}
		}
开发者ID:89sos98,项目名称:monodroid-samples,代码行数:17,代码来源:RichPushWidgetUtils.cs

示例5: RefreshWidget

		/**
     * Sends a request to the rich push message to refresh with a delay
     * @param context Application context
     * @param delayInMs Delay to wait in milliseconds before sending the request
     */
		public static void RefreshWidget(Context context, long delayInMs) {
			Intent refreshIntent = new Intent(context, typeof (RichPushWidgetProvider));
			refreshIntent.SetAction (RichPushWidgetProvider.REFRESH_ACTION);

			if (delayInMs > 0) {
				PendingIntent pendingIntent = PendingIntent.GetBroadcast(context, 0, refreshIntent, 0);
				AlarmManager am = (AlarmManager) context.GetSystemService(Context.AlarmService);
				am.Set (AlarmType.RtcWakeup, Java.Lang.JavaSystem.CurrentTimeMillis() + delayInMs, pendingIntent);
			} else {
				context.SendBroadcast(refreshIntent);
			}
		}
开发者ID:Appercode,项目名称:monodroid-samples,代码行数:17,代码来源:RichPushWidgetUtils.cs

示例6: TriggerRequest

 public static void TriggerRequest(Context ctx, string pkgName, PluginDatabase pluginDatabase)
 {
     try
     {
         Intent triggerIntent = new Intent(Strings.ActionTriggerRequestAccess);
         triggerIntent.SetPackage(pkgName);
         triggerIntent.PutExtra(Strings.ExtraSender, ctx.PackageName);
         string requestToken = pluginDatabase.GetRequestToken(pkgName);
         triggerIntent.PutExtra(Strings.ExtraRequestToken, requestToken);
         Android.Util.Log.Debug(_tag, "Request token: " + requestToken);
         ctx.SendBroadcast(triggerIntent);
     }
     catch (Exception e)
     {
     }
 }
开发者ID:pythe,项目名称:wristpass,代码行数:16,代码来源:PluginHost.cs

示例7: OnReceive

        public override void OnReceive(Context context, Intent intent)
        {
            PluginDatabase pluginDb = new PluginDatabase(context);
            if (intent.Action == Strings.ActionRequestAccess)
            {
                var senderPackage = intent.GetStringExtra(Strings.ExtraSender);
                var requestToken = intent.GetStringExtra(Strings.ExtraRequestToken);

                var requestedScopes = intent.GetStringArrayListExtra(Strings.ExtraScopes);

                if (!AreScopesValid(requestedScopes))
                {
                    return;
                }

                if (pluginDb.GetRequestToken(senderPackage) != requestToken)
                {
                    Log.Warn(_tag, "Invalid requestToken!");
                    return;
                }
                string currentAccessToken = pluginDb.GetAccessToken(senderPackage);
                if ((currentAccessToken != null)
                    && (AccessManager.IsSubset(requestedScopes,
                                           pluginDb.GetPluginScopes(senderPackage))))
                {
                    //permission already there.
                    var i = new Intent(Strings.ActionReceiveAccess);
                    i.PutExtra(Strings.ExtraSender, context.PackageName);
                    i.PutExtra(Strings.ExtraAccessToken, currentAccessToken);
                    //TODO: Plugin should verify requestToken to make sure it doesn't receive accessTokens from malicious apps
                    i.PutExtra(Strings.ExtraRequestToken, requestToken);
                    i.SetPackage(senderPackage);
                    context.SendBroadcast(i);

                    Log.Debug(_tag, "Plugin " + senderPackage + " enabled.");
                }
                else
                {
                    //store that scope was requested but not yet approved (=> accessToken = null)
                    pluginDb.StorePlugin(senderPackage, null, requestedScopes);

                    Log.Debug(_tag, "Plugin " + senderPackage + " not enabled.");

                    //see if the plugin has an access token
                    string accessToken = intent.GetStringExtra(Strings.ExtraAccessToken);
                    if (accessToken != null)
                    {
                        //notify plugin that access token is no longer valid or sufficient
                        Intent i = new Intent(Strings.ActionRevokeAccess);
                        i.PutExtra(Strings.ExtraSender, context.PackageName);
                        i.PutExtra(Strings.ExtraAccessToken, accessToken);
                        i.SetPackage(senderPackage);
                        context.SendBroadcast(i);
                        Log.Warn(_tag, "Access token of plugin " + senderPackage + " not (or no more) valid.");
                    }

                }
                if (OnReceivedRequest != null)
                    OnReceivedRequest(this, new PluginHostEventArgs() { Package = senderPackage });

            }
        }
开发者ID:pythe,项目名称:wristpass,代码行数:62,代码来源:PluginHost.cs

示例8: OnReceive

        public override void OnReceive(Context context, Intent intent)
        {
            String action = intent.Action;

            //check if we have a last opened entry
            //this should always be non-null, but if the OS has killed the app, it might occur.
            if (App.Kp2a.GetDb().LastOpenedEntry == null)
            {
                Intent i = new Intent(context, typeof(AppKilledInfo));
                i.SetFlags(ActivityFlags.ClearTask | ActivityFlags.NewTask);
                context.StartActivity(i);
                return;
            }

            if (action.Equals(Intents.CopyUsername))
            {
                String username = App.Kp2a.GetDb().LastOpenedEntry.OutputStrings.ReadSafe(PwDefs.UserNameField);
                if (username.Length > 0)
                {
                    CopyToClipboardService.CopyValueToClipboardWithTimeout(context, username);
                }
                context.SendBroadcast(new Intent(Intent.ActionCloseSystemDialogs)); //close notification drawer
            }
            else if (action.Equals(Intents.CopyPassword))
            {
                String password = App.Kp2a.GetDb().LastOpenedEntry.OutputStrings.ReadSafe(PwDefs.PasswordField);
                if (password.Length > 0)
                {
                    CopyToClipboardService.CopyValueToClipboardWithTimeout(context, password);
                }
                context.SendBroadcast(new Intent(Intent.ActionCloseSystemDialogs)); //close notification drawer
            }
            else if (action.Equals(Intents.CheckKeyboard))
            {
                CopyToClipboardService.ActivateKeyboard(context);
            }
        }
开发者ID:pythe,项目名称:wristpass,代码行数:37,代码来源:CopyToClipboardService.cs

示例9: RefreshWidget

        public static void RefreshWidget (Context ctx, string action, long delayInMs)
        {
            //Sends a request to the rich push message to refresh with a delay.
            var refreshIntent = new Intent (ctx, typeof (WidgetProvider));
            refreshIntent.SetAction (action);

            if (delayInMs > 0) {
                PendingIntent pendingIntent = PendingIntent.GetBroadcast (ctx, 0, refreshIntent, 0);
                var am = (AlarmManager) ctx.GetSystemService (Context.AlarmService);
                am.Set (AlarmType.RtcWakeup, (long) new TimeSpan (DateTime.Now.Ticks).TotalMilliseconds + delayInMs, pendingIntent);
            } else {
                ctx.SendBroadcast (refreshIntent);
            }
        }
开发者ID:VDBBjorn,项目名称:toggl_mobile,代码行数:14,代码来源:WidgetProvider.cs

示例10: TriggerRequest

        public static void TriggerRequest(Context ctx, string pkgName, PluginDatabase pluginDatabase)
        {
            try
            {
                Intent triggerIntent = new Intent(Strings.ActionTriggerRequestAccess);
                triggerIntent.SetPackage(pkgName);
                triggerIntent.PutExtra(Strings.ExtraSender, ctx.PackageName);

                triggerIntent.PutExtra(Strings.ExtraRequestToken, pluginDatabase.GetRequestToken(pkgName));
                ctx.SendBroadcast(triggerIntent);
            }
            catch (Exception e)
            {
            }
        }
开发者ID:pythe,项目名称:wristpass,代码行数:15,代码来源:PluginHost.cs


注:本文中的Android.Content.Context.SendBroadcast方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。