IntentCompat

public final class IntentCompat
extends Object

java.lang.Object
   ↳ androidx.core.content.IntentCompat


Helper for accessing features in Intent.

Summary

Constants

String ACTION_CREATE_REMINDER

Activity Action: Creates a reminder.

String ACTION_UNUSED_APP_RESTRICTIONS

Activity action: creates an intent to redirect the user to UI to turn on/off their unused app restriction settings.

int APP_HIBERNATION_DISABLED

App hibernation is disabled for this app (i.e.

int APP_HIBERNATION_ENABLED

App hibernation is enabled for this app (i.e.

String CATEGORY_LEANBACK_LAUNCHER

Indicates an activity optimized for Leanback mode, and that should be displayed in the Leanback launcher.

String EXTRA_HTML_TEXT

A constant String that is associated with the Intent, used with Intent.ACTION_SEND to supply an alternative to Intent.EXTRA_TEXT as HTML formatted text.

String EXTRA_START_PLAYBACK

Used as a boolean extra field in Intent.ACTION_VIEW intents to indicate that content should immediately be played without any intermediate screens that require additional user input, e.g.

String EXTRA_TIME

Optional extra specifying a time in milliseconds since the Epoch.

int PERMISSION_REVOCATION_DISABLED

Permission revocation is disabled for this app (i.e.

int PERMISSION_REVOCATION_ENABLED

Permission revocation is enabled for this app (i.e.

int UNUSED_APP_RESTRICTION_FEATURE_NOT_AVAILABLE

There are no available Unused App Restrictions features for this app.

int UNUSED_APP_RESTRICTION_STATUS_UNKNOWN

The status of Unused App Restrictions features is unknown for this app.

Public methods

static Intent createManageUnusedAppRestrictionsIntent(Context context, String packageName)

Make an Intent to redirect the user to UI to manage their unused app restriction settings for a particular app (e.g.

static int getUnusedAppRestrictionsStatus(Context context)

Returns the status of Unused App Restriction features for the current application, i.e.

static Intent makeMainSelectorActivity(String selectorAction, String selectorCategory)

Make an Intent for the main activity of an application, without specifying a specific activity to run but giving a selector to find the activity.

Inherited methods

Constants

ACTION_CREATE_REMINDER

public static final String ACTION_CREATE_REMINDER

Activity Action: Creates a reminder.

Input: Intent.EXTRA_TITLE The title of the reminder that will be shown to the user. Intent.EXTRA_TEXT The reminder text that will be shown to the user. The intent should at least specify a title or a text. EXTRA_TIME The time when the reminder will be shown to the user. The time is specified in milliseconds since the Epoch (optional).

Output: Nothing.

Constant Value: "android.intent.action.CREATE_REMINDER"

ACTION_UNUSED_APP_RESTRICTIONS

public static final String ACTION_UNUSED_APP_RESTRICTIONS

Activity action: creates an intent to redirect the user to UI to turn on/off their unused app restriction settings.

Constant Value: "android.intent.action.AUTO_REVOKE_PERMISSIONS"

APP_HIBERNATION_DISABLED

public static final int APP_HIBERNATION_DISABLED

App hibernation is disabled for this app (i.e. this app is exempt from being hibernated). Note: this also means that permission revocation is disabled for this app.

Constant Value: 5 (0x00000005)

APP_HIBERNATION_ENABLED

public static final int APP_HIBERNATION_ENABLED

App hibernation is enabled for this app (i.e. this app will be hibernated and have its permissions revoked if the app is unused). Note: this also means that permission revocation is enabled for this app.

Constant Value: 4 (0x00000004)

CATEGORY_LEANBACK_LAUNCHER

public static final String CATEGORY_LEANBACK_LAUNCHER

Indicates an activity optimized for Leanback mode, and that should be displayed in the Leanback launcher.

Constant Value: "android.intent.category.LEANBACK_LAUNCHER"

EXTRA_HTML_TEXT

public static final String EXTRA_HTML_TEXT

A constant String that is associated with the Intent, used with Intent.ACTION_SEND to supply an alternative to Intent.EXTRA_TEXT as HTML formatted text. Note that you must also supply Intent.EXTRA_TEXT.

Constant Value: "android.intent.extra.HTML_TEXT"

EXTRA_START_PLAYBACK

public static final String EXTRA_START_PLAYBACK

Used as a boolean extra field in Intent.ACTION_VIEW intents to indicate that content should immediately be played without any intermediate screens that require additional user input, e.g. a profile selection screen or a details page.

Constant Value: "android.intent.extra.START_PLAYBACK"

EXTRA_TIME

public static final String EXTRA_TIME

Optional extra specifying a time in milliseconds since the Epoch. The value must be non-negative.

Type: long

Constant Value: "android.intent.extra.TIME"

PERMISSION_REVOCATION_DISABLED

public static final int PERMISSION_REVOCATION_DISABLED

Permission revocation is disabled for this app (i.e. this app is exempt from having its permissions automatically removed). Note: this also means that app hibernation is not available for this app.

Constant Value: 3 (0x00000003)

PERMISSION_REVOCATION_ENABLED

public static final int PERMISSION_REVOCATION_ENABLED

Permission revocation is enabled for this app (i.e. permissions will be automatically reset if the app is unused). Note: this also means that app hibernation is not available for this app.

Constant Value: 2 (0x00000002)

UNUSED_APP_RESTRICTION_FEATURE_NOT_AVAILABLE

public static final int UNUSED_APP_RESTRICTION_FEATURE_NOT_AVAILABLE

There are no available Unused App Restrictions features for this app.

Constant Value: 1 (0x00000001)

UNUSED_APP_RESTRICTION_STATUS_UNKNOWN

public static final int UNUSED_APP_RESTRICTION_STATUS_UNKNOWN

The status of Unused App Restrictions features is unknown for this app.

Constant Value: 0 (0x00000000)

Public methods

createManageUnusedAppRestrictionsIntent

public static Intent createManageUnusedAppRestrictionsIntent (Context context, 
                String packageName)

Make an Intent to redirect the user to UI to manage their unused app restriction settings for a particular app (e.g. permission revocation, app hibernation). Note: developers must first call getUnusedAppRestrictionsStatus(Context) to make sure that unused app restriction features are available on the device before attempting to create an intent using this method. Any return value of this method besides UNUSED_APP_RESTRICTION_FEATURE_NOT_AVAILABLE indicates that at least one unused app restriction feature is available on the device. If the return value _is_ UNUSED_APP_RESTRICTION_FEATURE_NOT_AVAILABLE, this method will throw an UnsupportedOperationException. Compatibility behavior:

  • SDK 31 and above, this method generates an intent with action Intent .ACTION_APPLICATION_DETAILS_SETTINGS and packageName as data.
  • SDK 30, this method generates an intent with action Intent .ACTION_AUTO_REVOKE_PERMISSIONS and packageName as data.
  • SDK 23 through 29, this method will generate an intent with action Intent.ACTION_AUTO_REVOKE_PERMISSIONS and the package as the app with the Verifier role that can resolve the intent.
  • SDK 22 and below, this method will throw an UnsupportedOperationException

Parameters
context Context: The Context of the calling application.

packageName String: The package name of the calling application.

Returns
Intent Returns a newly created Intent that can be used to launch an activity where users can manage unused app restrictions for a specific app.

getUnusedAppRestrictionsStatus

public static int getUnusedAppRestrictionsStatus (Context context)

Returns the status of Unused App Restriction features for the current application, i.e. whether the features are available and if so, enabled for the application. Compatibility behavior:

Parameters
context Context

Returns
int

makeMainSelectorActivity

public static Intent makeMainSelectorActivity (String selectorAction, 
                String selectorCategory)

Make an Intent for the main activity of an application, without specifying a specific activity to run but giving a selector to find the activity. This results in a final Intent that is structured the same as when the application is launched from Home. For anything else that wants to launch an application in the same way, it is important that they use an Intent structured the same way, and can use this function to ensure this is the case.

The returned Intent has Intent.ACTION_MAIN as its action, and includes the category Intent.CATEGORY_LAUNCHER. This does not have Intent.FLAG_ACTIVITY_NEW_TASK set, though typically you will want to do that through Intent.addFlags(int) on the returned Intent.

Parameters
selectorAction String: The action name of the Intent's selector.

selectorCategory String: The name of a category to add to the Intent's selector.

Returns
Intent Returns a newly created Intent that can be used to launch the activity as a main application entry.