/** * Retrieve a PendingIntent that will start a service, like calling {@link Context#startService * Context.startService()}. The start arguments given to the service will come from the extras of * the Intent. * * <p class="note">For security reasons, the {@link android.content.Intent} you supply here should * almost always be an <em>explicit intent</em>, that is specify an explicit component to be * delivered to through {@link Intent#setClass(android.content.Context, Class) Intent.setClass} * * @param context The Context in which this PendingIntent should start the service. * @param requestCode Private request code for the sender * @param intent An Intent describing the service to be started. * @param flags May be {@link #FLAG_ONE_SHOT}, {@link #FLAG_NO_CREATE}, {@link * #FLAG_CANCEL_CURRENT}, {@link #FLAG_UPDATE_CURRENT}, or any of the flags as supported by * {@link Intent#fillIn Intent.fillIn()} to control which unspecified parts of the intent that * can be supplied when the actual send happens. * @return Returns an existing or new PendingIntent matching the given parameters. May return null * only if {@link #FLAG_NO_CREATE} has been supplied. */ public static PendingIntent getService( Context context, int requestCode, @NonNull Intent intent, @Flags int flags) { String packageName = context.getPackageName(); String resolvedType = intent != null ? intent.resolveTypeIfNeeded(context.getContentResolver()) : null; try { intent.prepareToLeaveProcess(); IIntentSender target = ActivityManagerNative.getDefault() .getIntentSender( ActivityManager.INTENT_SENDER_SERVICE, packageName, null, null, requestCode, new Intent[] {intent}, resolvedType != null ? new String[] {resolvedType} : null, flags, null, UserHandle.myUserId()); return target != null ? new PendingIntent(target) : null; } catch (RemoteException e) { } return null; }
/** * @hide Note that UserHandle.CURRENT will be interpreted at the time the activity is started, not * when the pending intent is created. */ public static PendingIntent getActivityAsUser( Context context, int requestCode, @NonNull Intent intent, int flags, Bundle options, UserHandle user) { String packageName = context.getPackageName(); String resolvedType = intent != null ? intent.resolveTypeIfNeeded(context.getContentResolver()) : null; try { intent.migrateExtraStreamToClipData(); intent.prepareToLeaveProcess(); IIntentSender target = ActivityManagerNative.getDefault() .getIntentSender( ActivityManager.INTENT_SENDER_ACTIVITY, packageName, null, null, requestCode, new Intent[] {intent}, resolvedType != null ? new String[] {resolvedType} : null, flags, options, user.getIdentifier()); return target != null ? new PendingIntent(target) : null; } catch (RemoteException e) { } return null; }
/** * @hide Note that UserHandle.CURRENT will be interpreted at the time the broadcast is sent, not * when the pending intent is created. */ public static PendingIntent getBroadcastAsUser( Context context, int requestCode, Intent intent, int flags, UserHandle userHandle) { String packageName = context.getPackageName(); String resolvedType = intent != null ? intent.resolveTypeIfNeeded(context.getContentResolver()) : null; try { intent.prepareToLeaveProcess(); IIntentSender target = ActivityManagerNative.getDefault() .getIntentSender( ActivityManager.INTENT_SENDER_BROADCAST, packageName, null, null, requestCode, new Intent[] {intent}, resolvedType != null ? new String[] {resolvedType} : null, flags, null, userHandle.getIdentifier()); return target != null ? new PendingIntent(target) : null; } catch (RemoteException e) { } return null; }
/** * @hide Ask that a new activity be started for voice interaction. This will create a new * dedicated task in the activity manager for this voice interaction session; this means that * {@link Intent#FLAG_ACTIVITY_NEW_TASK Intent.FLAG_ACTIVITY_NEW_TASK} will be set for you to * make it a new task. * <p>The newly started activity will be displayed to the user in a special way, as a layer * under the voice interaction UI. * <p>As the voice activity runs, it can retrieve a {@link android.app.VoiceInteractor} * through which it can perform voice interactions through your session. These requests for * voice interactions will appear as callbacks on {@link #onGetSupportedCommands}, {@link * #onConfirm}, {@link #onCommand}, and {@link #onCancel}. * <p>You will receive a call to {@link #onTaskStarted} when the task starts up and {@link * #onTaskFinished} when the last activity has finished. * @param intent The Intent to start this voice interaction. The given Intent will always have * {@link Intent#CATEGORY_VOICE Intent.CATEGORY_VOICE} added to it, since this is part of a * voice interaction. */ @SystemApi public void startVoiceActivity(Intent intent) { if (mToken == null) { throw new IllegalStateException("Can't call before onCreate()"); } try { intent.migrateExtraStreamToClipData(); intent.prepareToLeaveProcess(); int res = mSystemService.startVoiceActivity( mToken, intent, intent.resolveType(mContext.getContentResolver())); Instrumentation.checkStartActivityResult(res, intent); } catch (RemoteException e) { } }