RoleManager  |  API reference  |  Android Developers (original) (raw)


public final class RoleManager
extends [Object](/reference/java/lang/Object) ``


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(String)](/reference/android/app/role/RoleManager#isRoleAvailable%28java.lang.String%29) 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)](/reference/android/app/Activity#startActivityForResult%28android.content.Intent,%20int%29) with theIntent obtained from [createRequestRoleIntent(String)](/reference/android/app/role/RoleManager#createRequestRoleIntent%28java.lang.String%29).

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
String ROLE_ASSISTANT The name of the assistant app role.
String ROLE_BROWSER The name of the browser role.
String ROLE_CALL_REDIRECTION The name of the call redirection role.
String ROLE_CALL_SCREENING The name of the call screening and caller id role.
String ROLE_DIALER The name of the dialer role.
String ROLE_EMERGENCY The name of the emergency role
String ROLE_HOME The name of the home role.
String ROLE_NOTES The name of the notes role.
String ROLE_SMS The name of the SMS role.
String ROLE_WALLET The name of the Wallet role.
Public methods
Intent createRequestRoleIntent(String roleName) Returns an Intent suitable for passing toandroid.app.Activity.startActivityForResult(Intent,int) which prompts the user to grant a role to this application.
boolean isRoleAvailable(String roleName) Check whether a role is available in the system.
boolean isRoleHeld(String roleName) Check whether the calling application is holding a particular role.
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. finalClass<?> 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 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 wait(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 wait() Causes the current thread to wait until it is awakened, typically by being notified or interrupted.

Constants

ROLE_ASSISTANT

public static final String ROLE_ASSISTANT

The name of the assistant app role.

Constant Value: "android.app.role.ASSISTANT"

ROLE_BROWSER

public static final String ROLE_BROWSER

The name of the browser role.

Constant Value: "android.app.role.BROWSER"

ROLE_CALL_REDIRECTION

public static final String ROLE_CALL_REDIRECTION

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.

Constant Value: "android.app.role.CALL_REDIRECTION"

ROLE_CALL_SCREENING

public static final String ROLE_CALL_SCREENING

The name of the call screening and caller id role.

Constant Value: "android.app.role.CALL_SCREENING"

ROLE_DIALER

public static final String ROLE_DIALER

The name of the dialer role.

Constant Value: "android.app.role.DIALER"

ROLE_EMERGENCY

public static final String ROLE_EMERGENCY

The name of the emergency role

Constant Value: "android.app.role.EMERGENCY"

ROLE_HOME

public static final String ROLE_HOME

The name of the home role.

Constant Value: "android.app.role.HOME"

ROLE_NOTES

public static final String ROLE_NOTES

The name of the notes role.

Constant Value: "android.app.role.NOTES"

ROLE_SMS

public static final String ROLE_SMS

The name of the SMS role.

Constant Value: "android.app.role.SMS"

ROLE_WALLET

public static final String ROLE_WALLET

The name of the Wallet role.

Constant Value: "android.app.role.WALLET"

Public methods

isRoleAvailable

public boolean isRoleAvailable (String roleName)

Check whether a role is available in the system.

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

isRoleHeld

public boolean isRoleHeld (String roleName)

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.
Returns
boolean whether the calling application is holding the role