CrossProfileApps

public class CrossProfileApps
extends Object

java.lang.Object
   ↳ android.content.pm.CrossProfileApps


Class for handling cross profile operations. Apps can use this class to interact with its instance in any profile that is in getTargetUserProfiles(). For example, app can use this class to start its main activity in managed profile.

Summary

Public methods

Drawable getProfileSwitchingIconDrawable(UserHandle userHandle)

Return a drawable that calling app can show to user for the semantic of profile switching -- launching its own activity in specified user profile.

CharSequence getProfileSwitchingLabel(UserHandle userHandle)

Return a label that calling app can show to user for the semantic of profile switching -- launching its own activity in specified user profile.

List<UserHandle> getTargetUserProfiles()

Return a list of user profiles that that the caller can use when calling other APIs in this class.

void startMainActivity(ComponentName component, UserHandle targetUser)

Starts the specified main activity of the caller package in the specified profile.

Inherited methods

Public methods

getProfileSwitchingIconDrawable

Drawable getProfileSwitchingIconDrawable (UserHandle userHandle)

Return a drawable that calling app can show to user for the semantic of profile switching -- launching its own activity in specified user profile. For example, it may return a briefcase icon if the given user handle is the managed profile one.

Parameters
userHandle UserHandle: The UserHandle of the target profile, must be one of the users returned by getTargetUserProfiles(), otherwise a SecurityException will be thrown.

This value must never be null.

Returns
Drawable an icon that calling app can show user for the semantic of launching its own activity in specified user profile.

This value will never be null.

getProfileSwitchingLabel

CharSequence getProfileSwitchingLabel (UserHandle userHandle)

Return a label that calling app can show to user for the semantic of profile switching -- launching its own activity in specified user profile. For example, it may return "Switch to work" if the given user handle is the managed profile one.

Parameters
userHandle UserHandle: The UserHandle of the target profile, must be one of the users returned by getTargetUserProfiles(), otherwise a SecurityException will be thrown.

This value must never be null.

Returns
CharSequence a label that calling app can show user for the semantic of launching its own activity in the specified user profile.

This value will never be null.

getTargetUserProfiles

List<UserHandle> getTargetUserProfiles ()

Return a list of user profiles that that the caller can use when calling other APIs in this class.

A user profile would be considered as a valid target user profile, provided that:

  • It gets caller app installed
  • It is not equal to the calling user
  • It is in the same profile group of calling user profile
  • It is enabled

Returns
List<UserHandle>

This value will never be null.

See also:

startMainActivity

void startMainActivity (ComponentName component, 
                UserHandle targetUser)

Starts the specified main activity of the caller package in the specified profile.

Parameters
component ComponentName: The ComponentName of the activity to launch, it must be exported and has action ACTION_MAIN, category CATEGORY_LAUNCHER. Otherwise, SecurityException will be thrown.

This value must never be null.

targetUser UserHandle: The UserHandle of the profile, must be one of the users returned by getTargetUserProfiles(), otherwise a SecurityException will be thrown.

This value must never be null.