# Print output for @column tags ?>
Developers

- Design
- Develop
- Distribute

Developer Console

## Most visited

## Recently visited

## Results for

Summary: Constants | Methods | Inherited Methods

# 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

### Constants
`String` | `ACTION_CAN_INTERACT_ACROSS_PROFILES_CHANGED` Broadcast signalling that the receiving app's permission to interact across profiles has changed.

### Public methods
`boolean` | `canInteractAcrossProfiles()` Returns whether the calling package can interact across profiles.
`boolean` | `canRequestInteractAcrossProfiles()` Returns whether the calling package can request to navigate the user to the relevant settings page to request user consent to interact across profiles.
`Intent` | `createRequestInteractAcrossProfilesIntent()` Returns an `Intent` to open the settings page that allows the user to decide whether the calling app can interact across profiles.
`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` | `startActivity(Intent intent, UserHandle targetUser, Activity callingActivity, Bundle options)` Starts the specified activity of the caller package in the specified profile.
`void` | `startActivity(Intent intent, UserHandle targetUser, Activity callingActivity)` Starts the specified activity of the caller package in the specified profile.
`void` | `startMainActivity(ComponentName component, UserHandle targetUser)` Starts the specified main activity of the caller package in the specified profile.

### Inherited methods
From class `java.lang.Object`
`Object` | `clone()` Creates and returns a copy of this object.
`boolean` | `equals(Object obj)` Indicates whether some other object is "equal to" this one.
`void` | `finalize()` Called by the garbage collector on an object when garbage collection determines that there are no more references to the object.
`final Class<?>` | `getClass()` Returns the runtime class of this `Object`.
`int` | `hashCode()` Returns a hash code value for the object.
`final void` | `notify()` Wakes up a single thread that is waiting on this object's monitor.
`final void` | `notifyAll()` Wakes up all threads that are waiting on this object's monitor.
`String` | `toString()` Returns a string representation of the object.
`final void` | `wait(long timeout, int nanos)` Causes the current thread to wait until another thread invokes the `notify()` method or the `notifyAll()` method for this object, or some other thread interrupts the current thread, or a certain amount of real time has elapsed.
`final void` | `wait(long timeout)` Causes the current thread to wait until either another thread invokes the `notify()` method or the `notifyAll()` method for this object, or a specified amount of time has elapsed.
`final void` | `wait()` Causes the current thread to wait until another thread invokes the `notify()` method or the `notifyAll()` method for this object.

## Constants

### ACTION_CAN_INTERACT_ACROSS_PROFILES_CHANGED

    public static final String ACTION_CAN_INTERACT_ACROSS_PROFILES_CHANGED

Broadcast signalling that the receiving app's permission to interact across profiles has changed. This includes the user, admin, or OEM changing their consent such that the permission for the app to interact across profiles has changed.

This broadcast is not sent when other circumstances result in a change to being able to interact across profiles in practice, such as the profile being turned off or removed, apps being uninstalled, etc. The methods `canInteractAcrossProfiles()` and `canRequestInteractAcrossProfiles()` can be used by apps prior to attempting to interact across profiles or attempting to request user consent to interact across profiles.

Apps that have set the `android:crossProfile` manifest attribute to `true` can receive this broadcast in manifest broadcast receivers. Otherwise, it can only be received by dynamically-registered broadcast receivers.

Constant Value: "android.content.pm.action.CAN_INTERACT_ACROSS_PROFILES_CHANGED"

## Public methods

### canInteractAcrossProfiles

    public boolean canInteractAcrossProfiles ()

Returns whether the calling package can interact across profiles.

Specifically, returns whether the following are all true:

- `getTargetUserProfiles()` returns a non-empty list for the calling user.
- The user has previously consented to cross-profile communication for the calling package.
- The calling package has either been whitelisted by default by the OEM or has been explicitly whitelisted by the admin via `DevicePolicyManager.setCrossProfilePackages(ComponentName, Set)`.

If `false`, the package's current ability to request user consent to interact across profiles can be checked with `canRequestInteractAcrossProfiles()`. If `true`, user consent can be obtained via `createRequestInteractAcrossProfilesIntent()`. The package can then listen to `ACTION_CAN_INTERACT_ACROSS_PROFILES_CHANGED` broadcasts.

Returns
`boolean` | true if the calling package can interact across profiles.

Throws
`SecurityException` | if `mContext.getPackageName()` does not belong to the calling UID.

### canRequestInteractAcrossProfiles

    public boolean canRequestInteractAcrossProfiles ()

Returns whether the calling package can request to navigate the user to the relevant settings page to request user consent to interact across profiles.

If `true`, the navigation intent can be obtained via `createRequestInteractAcrossProfilesIntent()`. The package can then listen to `ACTION_CAN_INTERACT_ACROSS_PROFILES_CHANGED` broadcasts.

Specifically, returns whether the following are all true:

- `UserManager#getEnabledProfileIds(int)` returns at least one other profile for the calling user.
- The calling app has requested `android.Manifest.permission.INTERACT_ACROSS_PROFILES` in its manifest.
- The calling app is not a profile owner within the profile group of the calling user.

Note that in order for the user to be able to grant the consent, the requesting package must be whitelisted by the admin or the OEM and installed in the other profile. If this is not the case the user will be shown a message explaining why they can't grant the consent.

Note that user consent could already be granted if given a return value of `true`. The package's current ability to interact across profiles can be checked with `canInteractAcrossProfiles()`.

Returns
`boolean` | true if the calling package can request to interact across profiles.

### createRequestInteractAcrossProfilesIntent

    public Intent createRequestInteractAcrossProfilesIntent ()

Returns an `Intent` to open the settings page that allows the user to decide whether the calling app can interact across profiles.

The method `canRequestInteractAcrossProfiles()` must be returning `true`.

Note that the user may already have given consent and the app may already be able to interact across profiles, even if `canRequestInteractAcrossProfiles()` is `true`. The current ability to interact across profiles is given by `canInteractAcrossProfiles()`.

Returns
`Intent` | an `Intent` to open the settings page that allows the user to decide whether the app can interact across profiles This value cannot be `null`.

Throws
`SecurityException` | if `mContext.getPackageName()` does not belong to the calling UID, or `canRequestInteractAcrossProfiles()` is `false`.

### getProfileSwitchingIconDrawable

    public 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 cannot 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 cannot be `null`.

See also:

- `startMainActivity(ComponentName, UserHandle)`

### getProfileSwitchingLabel

    public 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 cannot 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 cannot be `null`.

See also:

- `startMainActivity(ComponentName, UserHandle)`

### getTargetUserProfiles

    public 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 cannot be `null`.

See also:

- `UserManager.getUserProfiles()`

### startActivity

    public void startActivity (Intent intent,
                    UserHandle targetUser,
                    Activity callingActivity,
                    Bundle options)

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

The caller must have the `Manifest.permission.INTERACT_ACROSS_PROFILES`, `android.Manifest.permission#INTERACT_ACROSS_USERS`, or `android.Manifest.permission#INTERACT_ACROSS_USERS_FULL` permission. Both the caller and target user profiles must be in the same profile group. The target user must be a valid user returned from `getTargetUserProfiles()`.
Requires `Manifest.permission.INTERACT_ACROSS_PROFILES` or android.Manifest.permission.INTERACT_ACROSS_USERS

Parameters
`intent` | `Intent`: The intent to launch. A component in the caller package must be specified. This value cannot be `null`.
`targetUser` | `UserHandle`: The `UserHandle` of the profile; must be one of the users returned by `getTargetUserProfiles()` if different to the calling user, otherwise a `SecurityException` will be thrown. This value cannot be `null`.
`callingActivity` | `Activity`: The activity to start the new activity from for the purposes of passing back any result and deciding which task the new activity should belong to. If `null`, the activity will always be started in a new task and no result will be returned. This value may be `null`.
`options` | `Bundle`: The activity options or `null`. See `ActivityOptions`. This value may be `null`.

### startActivity

    public void startActivity (Intent intent,
                    UserHandle targetUser,
                    Activity callingActivity)

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

The caller must have the `Manifest.permission.INTERACT_ACROSS_PROFILES`, `android.Manifest.permission#INTERACT_ACROSS_USERS`, or `android.Manifest.permission#INTERACT_ACROSS_USERS_FULL` permission. Both the caller and target user profiles must be in the same profile group. The target user must be a valid user returned from `getTargetUserProfiles()`.
Requires `Manifest.permission.INTERACT_ACROSS_PROFILES` or android.Manifest.permission.INTERACT_ACROSS_USERS

Parameters
`intent` | `Intent`: The intent to launch. A component in the caller package must be specified. This value cannot be `null`.
`targetUser` | `UserHandle`: The `UserHandle` of the profile; must be one of the users returned by `getTargetUserProfiles()` if different to the calling user, otherwise a `SecurityException` will be thrown. This value cannot be `null`.
`callingActivity` | `Activity`: The activity to start the new activity from for the purposes of passing back any result and deciding which task the new activity should belong to. If `null`, the activity will always be started in a new task and no result will be returned. This value may be `null`.

### startMainActivity

    public 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 `Intent.ACTION_MAIN`, category `Intent.CATEGORY_LAUNCHER`. Otherwise, SecurityException will be thrown. This value cannot 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 cannot be `null`.

Full name *
Email address *
Company / developer name
One of your Play Store app URLs *
Which best describes your business:*
Apps
Games
Apps & Games
*
*