Added in [API level 28](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels) Summary: [Constants](https://developer.android.com/reference/android/content/pm/CrossProfileApps#constants) \| [Methods](https://developer.android.com/reference/android/content/pm/CrossProfileApps#pubmethods) \| [Inherited Methods](https://developer.android.com/reference/android/content/pm/CrossProfileApps#inhmethods)

# CrossProfileApps

*** ** * ** ***


`
public


class
CrossProfileApps
`


`

extends https://developer.android.com/reference/java/lang/Object


`

`


`

|---|---|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object) ||
| ↳ | android.content.pm.CrossProfileApps |

<br />

*** ** * ** ***

Class for handling cross profile operations. Apps can use this class to interact with its
instance in any profile that is in `https://developer.android.com/reference/android/content/pm/CrossProfileApps#getTargetUserProfiles()`. For example, app can
use this class to start its main activity in managed profile.


Restricted for SDK Runtime environment in API level 34.

## Summary

| ### Constants ||
|---|---|
| `https://developer.android.com/reference/java/lang/String` | `https://developer.android.com/reference/android/content/pm/CrossProfileApps#ACTION_CAN_INTERACT_ACROSS_PROFILES_CHANGED` Broadcast signalling that the receiving app's permission to interact across profiles has changed. |

| ### Public methods ||
|---|---|
| ` boolean` | ` https://developer.android.com/reference/android/content/pm/CrossProfileApps#canInteractAcrossProfiles()() ` Returns whether the calling package can interact across profiles. |
| ` boolean` | ` https://developer.android.com/reference/android/content/pm/CrossProfileApps#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. |
| ` https://developer.android.com/reference/android/content/Intent` | ` https://developer.android.com/reference/android/content/pm/CrossProfileApps#createRequestInteractAcrossProfilesIntent()() ` Returns an `https://developer.android.com/reference/android/content/Intent` to open the settings page that allows the user to decide whether the calling app can interact across profiles. |
| ` https://developer.android.com/reference/android/graphics/drawable/Drawable` | ` https://developer.android.com/reference/android/content/pm/CrossProfileApps#getProfileSwitchingIconDrawable(android.os.UserHandle)(https://developer.android.com/reference/android/os/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. |
| ` https://developer.android.com/reference/java/lang/CharSequence` | ` https://developer.android.com/reference/android/content/pm/CrossProfileApps#getProfileSwitchingLabel(android.os.UserHandle)(https://developer.android.com/reference/android/os/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. |
| ` https://developer.android.com/reference/java/util/List<https://developer.android.com/reference/android/os/UserHandle>` | ` https://developer.android.com/reference/android/content/pm/CrossProfileApps#getTargetUserProfiles()() ` Return a list of user profiles that that the caller can use when calling other APIs in this class. |
| ` boolean` | ` https://developer.android.com/reference/android/content/pm/CrossProfileApps#isManagedProfile(android.os.UserHandle)(https://developer.android.com/reference/android/os/UserHandle userHandle) ` Checks if the specified user is a managed profile. |
| ` boolean` | ` https://developer.android.com/reference/android/content/pm/CrossProfileApps#isProfile(android.os.UserHandle)(https://developer.android.com/reference/android/os/UserHandle userHandle) ` Checks if the specified user is a profile, i.e. |
| ` void` | ` https://developer.android.com/reference/android/content/pm/CrossProfileApps#startActivity(android.content.Intent,%20android.os.UserHandle,%20android.app.Activity,%20android.os.Bundle)(https://developer.android.com/reference/android/content/Intent intent, https://developer.android.com/reference/android/os/UserHandle targetUser, https://developer.android.com/reference/android/app/Activity callingActivity, https://developer.android.com/reference/android/os/Bundle options) ` Starts the specified activity of the caller package in the specified profile. |
| ` void` | ` https://developer.android.com/reference/android/content/pm/CrossProfileApps#startActivity(android.content.Intent,%20android.os.UserHandle,%20android.app.Activity)(https://developer.android.com/reference/android/content/Intent intent, https://developer.android.com/reference/android/os/UserHandle targetUser, https://developer.android.com/reference/android/app/Activity callingActivity) ` Starts the specified activity of the caller package in the specified profile. |
| ` void` | ` https://developer.android.com/reference/android/content/pm/CrossProfileApps#startMainActivity(android.content.ComponentName,%20android.os.UserHandle)(https://developer.android.com/reference/android/content/ComponentName component, https://developer.android.com/reference/android/os/UserHandle targetUser) ` Starts the specified main activity of the caller package in the specified profile. |
| ` void` | ` https://developer.android.com/reference/android/content/pm/CrossProfileApps#startMainActivity(android.content.ComponentName,%20android.os.UserHandle,%20android.app.Activity,%20android.os.Bundle)(https://developer.android.com/reference/android/content/ComponentName component, https://developer.android.com/reference/android/os/UserHandle targetUser, https://developer.android.com/reference/android/app/Activity callingActivity, https://developer.android.com/reference/android/os/Bundle options) ` Starts the specified main activity of the caller package in the specified profile, launching in the specified activity. |

| ### Inherited methods |
|---|---|
| From class ` https://developer.android.com/reference/java/lang/Object ` |---|---| | ` https://developer.android.com/reference/java/lang/Object` | ` https://developer.android.com/reference/java/lang/Object#clone()() ` Creates and returns a copy of this object. | | ` boolean` | ` https://developer.android.com/reference/java/lang/Object#equals(java.lang.Object)(https://developer.android.com/reference/java/lang/Object obj) ` Indicates whether some other object is "equal to" this one. | | ` void` | ` https://developer.android.com/reference/java/lang/Object#finalize()() ` Called by the garbage collector on an object when garbage collection determines that there are no more references to the object. | | ` final https://developer.android.com/reference/java/lang/Class<?>` | ` https://developer.android.com/reference/java/lang/Object#getClass()() ` Returns the runtime class of this `Object`. | | ` int` | ` https://developer.android.com/reference/java/lang/Object#hashCode()() ` Returns a hash code value for the object. | | ` final void` | ` https://developer.android.com/reference/java/lang/Object#notify()() ` Wakes up a single thread that is waiting on this object's monitor. | | ` final void` | ` https://developer.android.com/reference/java/lang/Object#notifyAll()() ` Wakes up all threads that are waiting on this object's monitor. | | ` https://developer.android.com/reference/java/lang/String` | ` https://developer.android.com/reference/java/lang/Object#toString()() ` Returns a string representation of the object. | | ` final void` | ` https://developer.android.com/reference/java/lang/Object#wait(long,%20int)(long timeoutMillis, int nanos) ` Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*, or until a certain amount of real time has elapsed. | | ` final void` | ` https://developer.android.com/reference/java/lang/Object#wait(long)(long timeoutMillis) ` Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*, or until a certain amount of real time has elapsed. | | ` final void` | ` https://developer.android.com/reference/java/lang/Object#wait()() ` Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*. | ||

## Constants

### ACTION_CAN_INTERACT_ACROSS_PROFILES_CHANGED

Added in [API level 30](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
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 `https://developer.android.com/reference/android/content/pm/CrossProfileApps#canInteractAcrossProfiles()` and `https://developer.android.com/reference/android/content/pm/CrossProfileApps#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.

<br />

Constant Value:

"android.content.pm.action.CAN_INTERACT_ACROSS_PROFILES_CHANGED"


## Public methods

### canInteractAcrossProfiles

Added in [API level 30](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public boolean canInteractAcrossProfiles ()
```

Returns whether the calling package can interact across profiles.

Specifically, returns whether the following are all true:

- `https://developer.android.com/reference/android/content/pm/CrossProfileApps#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 allowlisted by default by the OEM or has been explicitly allowlisted by the admin via `https://developer.android.com/reference/android/app/admin/DevicePolicyManager#setCrossProfilePackages(android.content.ComponentName,%20java.util.Set<java.lang.String>)`.

If `false`, the package's current ability to request user consent to interact across
profiles can be checked with `https://developer.android.com/reference/android/content/pm/CrossProfileApps#canRequestInteractAcrossProfiles()`. If `true`,
user consent can be obtained via `https://developer.android.com/reference/android/content/pm/CrossProfileApps#createRequestInteractAcrossProfilesIntent()`. The
package can then listen to `https://developer.android.com/reference/android/content/pm/CrossProfileApps#ACTION_CAN_INTERACT_ACROSS_PROFILES_CHANGED` broadcasts.

<br />

| Returns ||
|---|---|
| `boolean` | true if the calling package can interact across profiles. <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/lang/SecurityException` | if `mContext.getPackageName()` does not belong to the calling UID. |

### canRequestInteractAcrossProfiles

Added in [API level 30](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
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 `https://developer.android.com/reference/android/content/pm/CrossProfileApps#createRequestInteractAcrossProfilesIntent()`. The package can then listen to `https://developer.android.com/reference/android/content/pm/CrossProfileApps#ACTION_CAN_INTERACT_ACROSS_PROFILES_CHANGED` broadcasts.

Specifically, returns whether the following are all true:

- `UserManager#getProfileIdsExcludingHidden(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 allowlisted 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 `https://developer.android.com/reference/android/content/pm/CrossProfileApps#canInteractAcrossProfiles()`.

<br />

| Returns ||
|---|---|
| `boolean` | true if the calling package can request to interact across profiles. <br /> |

### createRequestInteractAcrossProfilesIntent

Added in [API level 30](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public Intent createRequestInteractAcrossProfilesIntent ()
```

Returns an `https://developer.android.com/reference/android/content/Intent` to open the settings page that allows the user to decide whether
the calling app can interact across profiles.

The method `https://developer.android.com/reference/android/content/pm/CrossProfileApps#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 `https://developer.android.com/reference/android/content/pm/CrossProfileApps#canRequestInteractAcrossProfiles()` is `true`. The current ability to interact across profiles is given by `https://developer.android.com/reference/android/content/pm/CrossProfileApps#canInteractAcrossProfiles()`.

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/content/Intent` | an `https://developer.android.com/reference/android/content/Intent` to open the settings page that allows the user to decide whether the app can interact across profiles. This value cannot be `null`. <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/lang/SecurityException` | if `mContext.getPackageName()` does not belong to the calling UID, or `https://developer.android.com/reference/android/content/pm/CrossProfileApps#canRequestInteractAcrossProfiles()` is `false`. |

### getProfileSwitchingIconDrawable

Added in [API level 28](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
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.

<br />

| Parameters ||
|---|---|
| `userHandle` | `UserHandle`: The UserHandle of the target profile, must be one of the users returned by `https://developer.android.com/reference/android/content/pm/CrossProfileApps#getTargetUserProfiles()`, otherwise a `https://developer.android.com/reference/java/lang/SecurityException` will be thrown. This value cannot be `null`. <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/graphics/drawable/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`. <br /> |

**See also:**

- `https://developer.android.com/reference/android/content/pm/CrossProfileApps#startMainActivity(android.content.ComponentName,%20android.os.UserHandle)`

### getProfileSwitchingLabel

Added in [API level 28](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
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.

<br />

| Parameters ||
|---|---|
| `userHandle` | `UserHandle`: The UserHandle of the target profile, must be one of the users returned by `https://developer.android.com/reference/android/content/pm/CrossProfileApps#getTargetUserProfiles()`, otherwise a `https://developer.android.com/reference/java/lang/SecurityException` will be thrown. This value cannot be `null`. <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/lang/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`. <br /> |

**See also:**

- `https://developer.android.com/reference/android/content/pm/CrossProfileApps#startMainActivity(android.content.ComponentName,%20android.os.UserHandle)`

### getTargetUserProfiles

Added in [API level 28](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
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
- It is not hidden (ex. profile type `https://developer.android.com/reference/android/os/UserManager#USER_TYPE_PROFILE_PRIVATE`)

<br />

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/util/List<https://developer.android.com/reference/android/os/UserHandle>` | This value cannot be `null`. <br /> |

**See also:**

- `https://developer.android.com/reference/android/os/UserManager#getUserProfiles()`

### isManagedProfile

Added in [API level 35](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public boolean isManagedProfile (UserHandle userHandle)
```

Checks if the specified user is a managed profile.

<br />

| Parameters ||
|---|---|
| `userHandle` | `UserHandle`: The UserHandle of the target profile, must be one of the users returned by `https://developer.android.com/reference/android/content/pm/CrossProfileApps#getTargetUserProfiles()`, otherwise a `https://developer.android.com/reference/java/lang/SecurityException` will be thrown. This value cannot be `null`. <br /> |

| Returns ||
|---|---|
| `boolean` | whether the specified user is a managed profile. <br /> |

### isProfile

Added in [API level 35](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public boolean isProfile (UserHandle userHandle)
```

Checks if the specified user is a profile, i.e. not the parent user.

<br />

| Parameters ||
|---|---|
| `userHandle` | `UserHandle`: The UserHandle of the target profile, must be one of the users returned by `https://developer.android.com/reference/android/content/pm/CrossProfileApps#getTargetUserProfiles()`, otherwise a `https://developer.android.com/reference/java/lang/SecurityException` will be thrown. This value cannot be `null`. <br /> |

| Returns ||
|---|---|
| `boolean` | whether the specified user is a profile. <br /> |

### startActivity

Added in [API level 30](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
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 `https://developer.android.com/reference/android/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 `https://developer.android.com/reference/android/content/pm/CrossProfileApps#getTargetUserProfiles()`.


Requires `https://developer.android.com/reference/android/Manifest.permission#INTERACT_ACROSS_PROFILES` or android.Manifest.permission.INTERACT_ACROSS_USERS

<br />

| Parameters ||
|---|---|
| `intent` | `Intent`: The intent to launch. A component in the caller package must be specified. This value cannot be `null`. <br /> |
| `targetUser` | `UserHandle`: The `https://developer.android.com/reference/android/os/UserHandle` of the profile; must be one of the users returned by `https://developer.android.com/reference/android/content/pm/CrossProfileApps#getTargetUserProfiles()` if different to the calling user, otherwise a `https://developer.android.com/reference/java/lang/SecurityException` will be thrown. This value cannot be `null`. <br /> |
| `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. <br /> |
| `options` | `Bundle`: The activity options or `null`. See `https://developer.android.com/reference/android/app/ActivityOptions`. <br /> |

### startActivity

Added in [API level 30](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
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 `https://developer.android.com/reference/android/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 `https://developer.android.com/reference/android/content/pm/CrossProfileApps#getTargetUserProfiles()`.


Requires `https://developer.android.com/reference/android/Manifest.permission#INTERACT_ACROSS_PROFILES` or android.Manifest.permission.INTERACT_ACROSS_USERS

<br />

| Parameters ||
|---|---|
| `intent` | `Intent`: The intent to launch. A component in the caller package must be specified. This value cannot be `null`. <br /> |
| `targetUser` | `UserHandle`: The `https://developer.android.com/reference/android/os/UserHandle` of the profile; must be one of the users returned by `https://developer.android.com/reference/android/content/pm/CrossProfileApps#getTargetUserProfiles()` if different to the calling user, otherwise a `https://developer.android.com/reference/java/lang/SecurityException` will be thrown. This value cannot be `null`. <br /> |
| `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. <br /> |

### startMainActivity

Added in [API level 28](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void startMainActivity (ComponentName component, 
                UserHandle targetUser)
```

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

<br />

| Parameters ||
|---|---|
| `component` | `ComponentName`: The ComponentName of the activity to launch, it must be exported and has action `https://developer.android.com/reference/android/content/Intent#ACTION_MAIN`, category `https://developer.android.com/reference/android/content/Intent#CATEGORY_LAUNCHER`. Otherwise, SecurityException will be thrown. This value cannot be `null`. <br /> |
| `targetUser` | `UserHandle`: The UserHandle of the profile, must be one of the users returned by `https://developer.android.com/reference/android/content/pm/CrossProfileApps#getTargetUserProfiles()`, otherwise a `https://developer.android.com/reference/java/lang/SecurityException` will be thrown. This value cannot be `null`. <br /> |

### startMainActivity

Added in [API level 33](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void startMainActivity (ComponentName component, 
                UserHandle targetUser, 
                Activity callingActivity, 
                Bundle options)
```

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

<br />

| Parameters ||
|---|---|
| `component` | `ComponentName`: The ComponentName of the activity to launch, it must be exported and has action `https://developer.android.com/reference/android/content/Intent#ACTION_MAIN`, category `https://developer.android.com/reference/android/content/Intent#CATEGORY_LAUNCHER`. Otherwise, SecurityException will be thrown. This value cannot be `null`. <br /> |
| `targetUser` | `UserHandle`: The UserHandle of the profile, must be one of the users returned by `https://developer.android.com/reference/android/content/pm/CrossProfileApps#getTargetUserProfiles()`, otherwise a `https://developer.android.com/reference/java/lang/SecurityException` will be thrown. This value cannot be `null`. <br /> |
| `callingActivity` | `Activity`: The activity to start the new activity from for the purposes of deciding which task the new activity should belong to. If `null`, the activity will always be started in a new task. <br /> |
| `options` | `Bundle`: The activity options or `null`. See `https://developer.android.com/reference/android/app/ActivityOptions`. <br /> |