Added in API level 29

RoleManager

class RoleManager
kotlin.Any
   ↳ android.app.role.RoleManager

This class provides information about and manages roles.

A role is a unique name within the system associated with certain privileges. The list of available roles might change with a system app update, so apps should not make assumption about the availability of roles. Instead, they should always query if the role is available using isRoleAvailable(java.lang.String) before trying to do anything with it. Some predefined role names are available as constants in this class, and a list of possibly available roles can be found in the AndroidX Role library.

There can be multiple applications qualifying for a role, but only a subset of them can become role holders. To qualify for a role, an application must meet certain requirements, including defining certain components in its manifest. These requirements can be found in the AndroidX Libraries. Then the application will need user consent to become a role holder, which can be requested using android.app.Activity#startActivityForResult(Intent, int) with the Intent obtained from createRequestRoleIntent(java.lang.String).

Upon becoming a role holder, the application may be granted certain privileges that are role specific. When the application loses its role, these privileges will also be revoked.

Summary

Constants
static String

The name of the assistant app role.

static String

The name of the browser role.

static String

The name of the call redirection role.

static String

The name of the call screening and caller id role.

static String

The name of the dialer role.

static String

The name of the emergency role

static String

The name of the home role.

static String

The name of the notes role.

static String

The name of the SMS role.

Public methods
Intent

Returns an Intent suitable for passing to android.app.Activity#startActivityForResult(Intent, int) which prompts the user to grant a role to this application.

Boolean

Check whether a role is available in the system.

Boolean
isRoleHeld(roleName: String)

Check whether the calling application is holding a particular role.

Constants

ROLE_ASSISTANT

Added in API level 29
static val ROLE_ASSISTANT: String

The name of the assistant app role.

Value: "android.app.role.ASSISTANT"

ROLE_BROWSER

Added in API level 29
static val ROLE_BROWSER: String

The name of the browser role.

Value: "android.app.role.BROWSER"

ROLE_CALL_REDIRECTION

Added in API level 29
static val ROLE_CALL_REDIRECTION: String

The name of the call redirection role.

A call redirection app provides a means to re-write the phone number for an outgoing call to place the call through a call redirection service.

Value: "android.app.role.CALL_REDIRECTION"

ROLE_CALL_SCREENING

Added in API level 29
static val ROLE_CALL_SCREENING: String

The name of the call screening and caller id role.

Value: "android.app.role.CALL_SCREENING"

ROLE_DIALER

Added in API level 29
static val ROLE_DIALER: String

The name of the dialer role.

Value: "android.app.role.DIALER"

ROLE_EMERGENCY

Added in API level 29
static val ROLE_EMERGENCY: String

The name of the emergency role

Value: "android.app.role.EMERGENCY"

ROLE_HOME

Added in API level 29
static val ROLE_HOME: String

The name of the home role.

Value: "android.app.role.HOME"

ROLE_NOTES

Added in API level 34
static val ROLE_NOTES: String

The name of the notes role.

Value: "android.app.role.NOTES"

ROLE_SMS

Added in API level 29
static val ROLE_SMS: String

The name of the SMS role.

Value: "android.app.role.SMS"

Public methods

createRequestRoleIntent

Added in API level 29
fun createRequestRoleIntent(roleName: String): Intent

Returns an Intent suitable for passing to android.app.Activity#startActivityForResult(Intent, int) which prompts the user to grant a role to this application.

If the role is granted, the resultCode will be android.app.Activity#RESULT_OK, otherwise it will be android.app.Activity#RESULT_CANCELED.

Parameters
roleName String: the name of requested role This value cannot be null.
Return
Intent the Intent to prompt user to grant the role This value cannot be null.

isRoleAvailable

Added in API level 29
fun isRoleAvailable(roleName: String): Boolean

Check whether a role is available in the system.

Parameters
roleName String: the name of role to checking for This value cannot be null.
Return
Boolean whether the role is available in the system

isRoleHeld

Added in API level 29
fun isRoleHeld(roleName: String): Boolean

Check whether the calling application is holding a particular role.

Parameters
roleName String: the name of the role to check for This value cannot be null.
Return
Boolean whether the calling application is holding the role