IntentCompat

Added in 1.1.0

public final class IntentCompat


Helper for accessing features in Intent.

Summary

Constants

static final String
ACTION_CREATE_REMINDER = "android.intent.action.CREATE_REMINDER"

Activity Action: Creates a reminder.

static final String
CATEGORY_LEANBACK_LAUNCHER = "android.intent.category.LEANBACK_LAUNCHER"

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

static final String
EXTRA_HTML_TEXT = "android.intent.extra.HTML_TEXT"

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

static final String
EXTRA_START_PLAYBACK = "android.intent.extra.START_PLAYBACK"

Used as a boolean extra field in 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.

static final String
EXTRA_TIME = "android.intent.extra.TIME"

Optional extra specifying a time in milliseconds since the Epoch.

Public methods

static @NonNull Intent
createManageUnusedAppRestrictionsIntent(
    @NonNull Context context,
    @NonNull 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).

static @Nullable Parcelable[]
getParcelableArrayExtra(
    @NonNull Intent in,
    @Nullable String name,
    @NonNull Class<Parcelable> clazz
)

Retrieve extended data from the intent.

static @Nullable ArrayList<T>
<T> getParcelableArrayListExtra(
    @NonNull Intent in,
    @Nullable String name,
    @NonNull Class<T> clazz
)

Retrieve extended data from the intent.

static @Nullable T
<T> getParcelableExtra(
    @NonNull Intent in,
    @Nullable String name,
    @NonNull Class<T> clazz
)

Retrieve extended data from the intent.

static @Nullable T
<T extends Serializable> getSerializableExtra(
    @NonNull Intent in,
    @Nullable String key,
    @NonNull Class<T> clazz
)

Returns the value associated with the given key or null if:

static @NonNull Intent
makeMainSelectorActivity(
    @NonNull String selectorAction,
    @NonNull 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.

Constants

ACTION_CREATE_REMINDER

Added in 1.5.0
public static final String ACTION_CREATE_REMINDER = "android.intent.action.CREATE_REMINDER"

Activity Action: Creates a reminder.

Input: EXTRA_TITLE The title of the reminder that will be shown to the user. 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.

CATEGORY_LEANBACK_LAUNCHER

Added in 1.1.0
public static final String CATEGORY_LEANBACK_LAUNCHER = "android.intent.category.LEANBACK_LAUNCHER"

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

EXTRA_HTML_TEXT

Added in 1.1.0
public static final String EXTRA_HTML_TEXT = "android.intent.extra.HTML_TEXT"

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

EXTRA_START_PLAYBACK

Added in 1.1.0
public static final String EXTRA_START_PLAYBACK = "android.intent.extra.START_PLAYBACK"

Used as a boolean extra field in 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.

EXTRA_TIME

Added in 1.5.0
public static final String EXTRA_TIME = "android.intent.extra.TIME"

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

Type: long

Public methods

createManageUnusedAppRestrictionsIntent

Added in 1.7.0
public static @NonNull Intent createManageUnusedAppRestrictionsIntent(
    @NonNull Context context,
    @NonNull 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 to make sure that unused app restriction features are available on the device before attempting to create an intent using this method. Likewise, the returned intent must be sent using startActivityForResult, _not_ startActivity.

Any return value of getUnusedAppRestrictionsStatus besides FEATURE_NOT_AVAILABLE indicates that at least one unused app restriction feature is available on the device. If the return value _is_ FEATURE_NOT_AVAILABLE, this method will throw an UnsupportedOperationException.

If the return value is ERROR, then there was an issue when fetching whether the unused app restriction features on the device are enabled for this application. However, this method will still return an intent to redirect the user.

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 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
@NonNull Context context

The Context of the calling application.

@NonNull String packageName

The package name of the calling application.

Returns
@NonNull 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.

getParcelableArrayExtra

Added in 1.10.0
public static @Nullable Parcelable[] getParcelableArrayExtra(
    @NonNull Intent in,
    @Nullable String name,
    @NonNull Class<Parcelable> clazz
)

Retrieve extended data from the intent. Compatibility behavior:

  • SDK 34 and later, this method matches platform behavior.
  • SDK 33 and below, this method will not check the array elements' types.
Parameters
@NonNull Intent in

The intent to retrieve from.

@Nullable String name

The name of the desired item.

@NonNull Class<Parcelable> clazz

The type of the items inside the array. This is only verified when unparceling.

Returns
@Nullable Parcelable[]

the value of an item previously added with putExtra(), or null if no Parcelable[] value was found.

See also
putExtra

getParcelableArrayListExtra

Added in 1.10.0
public static @Nullable ArrayList<T> <T> getParcelableArrayListExtra(
    @NonNull Intent in,
    @Nullable String name,
    @NonNull Class<T> clazz
)

Retrieve extended data from the intent. Compatibility behavior:

  • SDK 34 and later, this method matches platform behavior.
  • SDK 33 and below, this method will not check the array elements' types.
Parameters
@NonNull Intent in

The intent to retrieve from.

@Nullable String name

The name of the desired item.

@NonNull Class<T> clazz

The type of the items inside the array list. This is only verified when unparceling.

Returns
@Nullable ArrayList<T>

the value of an item previously added with putParcelableArrayListExtra(), or null if no ArrayListvalue was found.

getParcelableExtra

Added in 1.10.0
public static @Nullable T <T> getParcelableExtra(
    @NonNull Intent in,
    @Nullable String name,
    @NonNull Class<T> clazz
)

Retrieve extended data from the intent. Compatibility behavior:

  • SDK 34 and later, this method matches platform behavior.
  • SDK 33 and below, the object type is checked after deserialization.
Parameters
@NonNull Intent in

The intent to retrieve from.

@Nullable String name

The name of the desired item.

@NonNull Class<T> clazz

The type of the object expected.

Returns
@Nullable T

the value of an item previously added with putExtra(), or null if no Parcelable value was found.

See also
putExtra

getSerializableExtra

public static @Nullable T <T extends Serializable> getSerializableExtra(
    @NonNull Intent in,
    @Nullable String key,
    @NonNull Class<T> clazz
)

Returns the value associated with the given key or null if:

  • No mapping of the desired type exists for the given key.
  • A null value is explicitly associated with the key.
  • The object is not of type clazz.
Compatibility behavior:
  • SDK 34 and above, this method matches platform behavior.
  • SDK 33 and below, the object type is checked after deserialization.
Parameters
@NonNull Intent in

The bundle to retrieve from.

@Nullable String key

a String, or null

@NonNull Class<T> clazz

The type of the object expected

Returns
@Nullable T

a Serializable value, or null

makeMainSelectorActivity

Added in 1.1.0
public static @NonNull Intent makeMainSelectorActivity(
    @NonNull String selectorAction,
    @NonNull 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 ACTION_MAIN as its action, and includes the category CATEGORY_LAUNCHER. This does not have FLAG_ACTIVITY_NEW_TASK set, though typically you will want to do that through addFlags on the returned Intent.

Parameters
@NonNull String selectorAction

The action name of the Intent's selector.

@NonNull String selectorCategory

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

Returns
@NonNull Intent

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