IntentCompat
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 |
static final String |
EXTRA_START_PLAYBACK = "android.intent.extra.START_PLAYBACK"Used as a boolean extra field in |
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(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(Retrieve extended data from the intent. |
static @Nullable ArrayList<T> |
<T> getParcelableArrayListExtra(Retrieve extended data from the intent. |
static @Nullable T |
Retrieve extended data from the intent. |
static @Nullable T |
<T extends Serializable> getSerializableExtra(Returns the value associated with the given key or |
static @NonNull Intent |
makeMainSelectorActivity(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
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.
| See also | |
|---|---|
EXTRA_TITLE |
|
EXTRA_TEXT |
|
EXTRA_TIME |
CATEGORY_LEANBACK_LAUNCHER
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
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
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
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
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_SETTINGSandpackageNameas data. - SDK 30, this method generates an intent with action
Intent .ACTION_AUTO_REVOKE_PERMISSIONSandpackageNameas data. - SDK 23 through 29, this method will generate an intent with action
ACTION_AUTO_REVOKE_PERMISSIONSand the package as the app with the Verifier role that can resolve the intent. - SDK 22 and below, this method will throw an
UnsupportedOperationException
getParcelableArrayExtra
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
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. |
| See also | |
|---|---|
putParcelableArrayListExtra |
getParcelableExtra
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
nullvalue is explicitly associated with the key. - The object is not of type
clazz.
- 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 |
@NonNull Class<T> clazz |
The type of the object expected |
| Returns | |
|---|---|
@Nullable T |
a Serializable value, or |
makeMainSelectorActivity
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.