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);
 }
Пример #2
0
 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);
 }
        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);
            }
        }
		/**
     * 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);
			}
		}
		/**
     * 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);
			}
		}
Пример #6
0
 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)
     {
     }
 }
Пример #7
0
        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 });

            }
        }
Пример #8
0
        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);
            }
        }
Пример #9
0
        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);
            }
        }
Пример #10
0
        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)
            {
            }
        }