IntentCompat

Added in 1.1.0

class IntentCompat


Helper for accessing features in Intent.

Summary

Constants

const String!
ACTION_CREATE_REMINDER = "android.intent.action.CREATE_REMINDER"

Activity Action: Creates a reminder.

const 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.

const 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.

const 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.

const String!
EXTRA_TIME = "android.intent.extra.TIME"

Optional extra specifying a time in milliseconds since the Epoch.

Public functions

java-static Intent
createManageUnusedAppRestrictionsIntent(
    context: Context,
    packageName: String
)

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).

java-static Array<Parcelable!>?

Retrieve extended data from the intent.

java-static ArrayList<T!>?
<T> getParcelableArrayListExtra(in: Intent, name: String?, clazz: Class<T!>)

Retrieve extended data from the intent.

java-static T?
<T> getParcelableExtra(in: Intent, name: String?, clazz: Class<T!>)

Retrieve extended data from the intent.

java-static T?
<T : Serializable?> getSerializableExtra(
    in: Intent,
    key: String?,
    clazz: Class<T!>
)

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

java-static Intent
makeMainSelectorActivity(
    selectorAction: String,
    selectorCategory: String
)

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
const val ACTION_CREATE_REMINDER = "android.intent.action.CREATE_REMINDER": String!

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
const val CATEGORY_LEANBACK_LAUNCHER = "android.intent.category.LEANBACK_LAUNCHER": String!

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

EXTRA_HTML_TEXT

Added in 1.1.0
const val EXTRA_HTML_TEXT = "android.intent.extra.HTML_TEXT": String!

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
const val EXTRA_START_PLAYBACK = "android.intent.extra.START_PLAYBACK": String!

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
const val EXTRA_TIME = "android.intent.extra.TIME": String!

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

Type: long

Public functions

createManageUnusedAppRestrictionsIntent

Added in 1.7.0
java-static fun createManageUnusedAppRestrictionsIntent(
    context: Context,
    packageName: String
): Intent

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
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.

getParcelableArrayExtra

Added in 1.10.0
java-static fun getParcelableArrayExtra(in: Intent, name: String?, clazz: Class<Parcelable!>): Array<Parcelable!>?

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
in: Intent

The intent to retrieve from.

name: String?

The name of the desired item.

clazz: Class<Parcelable!>

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

Returns
Array<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
java-static fun <T> getParcelableArrayListExtra(in: Intent, name: String?, clazz: Class<T!>): ArrayList<T!>?

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
in: Intent

The intent to retrieve from.

name: String?

The name of the desired item.

clazz: Class<T!>

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

Returns
ArrayList<T!>?

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

getParcelableExtra

Added in 1.10.0
java-static fun <T> getParcelableExtra(in: Intent, name: String?, clazz: Class<T!>): T?

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
in: Intent

The intent to retrieve from.

name: String?

The name of the desired item.

clazz: Class<T!>

The type of the object expected.

Returns
T?

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

See also
putExtra

getSerializableExtra

Added in 1.13.0
java-static fun <T : Serializable?> getSerializableExtra(
    in: Intent,
    key: String?,
    clazz: Class<T!>
): T?

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
in: Intent

The bundle to retrieve from.

key: String?

a String, or null

clazz: Class<T!>

The type of the object expected

Returns
T?

a Serializable value, or null

makeMainSelectorActivity

Added in 1.1.0
java-static fun makeMainSelectorActivity(
    selectorAction: String,
    selectorCategory: String
): Intent

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
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.