Added in API level 1

PendingIntent


class PendingIntent : Parcelable
kotlin.Any
   ↳ android.app.PendingIntent

A description of an Intent and target action to perform with it. Instances of this class are created with #getActivity, #getActivities, getBroadcast, and getService; the returned object can be handed to other applications so that they can perform the action you described on your behalf at a later time.

By giving a PendingIntent to another application, you are granting it the right to perform the operation you have specified as if the other application was yourself (with the same permissions and identity). As such, you should be careful about how you build the PendingIntent: almost always, for example, the base Intent you supply should have the component name explicitly set to one of your own components, to ensure it is ultimately sent there and nowhere else.

A PendingIntent itself is simply a reference to a token maintained by the system describing the original data used to retrieve it. This means that, even if its owning application's process is killed, the PendingIntent itself will remain usable from other processes that have been given it. If the creating application later re-retrieves the same kind of PendingIntent (same operation, same Intent action, data, categories, and components, and same flags), it will receive a PendingIntent representing the same token if that is still valid, and can thus call cancel to remove it.

Because of this behavior, it is important to know when two Intents are considered to be the same for purposes of retrieving a PendingIntent. A common mistake people make is to create multiple PendingIntent objects with Intents that only vary in their "extra" contents, expecting to get a different PendingIntent each time. This does not happen. The parts of the Intent that are used for matching are the same ones defined by Intent.filterEquals. If you use two Intent objects that are equivalent as per Intent.filterEquals, then you will get the same PendingIntent for both of them.

There are two typical ways to deal with this.

If you truly need multiple distinct PendingIntent objects active at the same time (such as to use as two notifications that are both shown at the same time), then you will need to ensure there is something that is different about them to associate them with different PendingIntents. This may be any of the Intent attributes considered by Intent.filterEquals, or different request code integers supplied to #getActivity, #getActivities, getBroadcast, or getService.

If you only need one PendingIntent active at a time for any of the Intents you will use, then you can alternatively use the flags FLAG_CANCEL_CURRENT or FLAG_UPDATE_CURRENT to either cancel or modify whatever current PendingIntent is associated with the Intent you are supplying.

Also note that flags like FLAG_ONE_SHOT or FLAG_IMMUTABLE describe the PendingIntent instance and thus, are used to identify it. Any calls to retrieve or modify a PendingIntent created with these flags will also require these flags to be supplied in conjunction with others. E.g. To retrieve an existing PendingIntent created with FLAG_ONE_SHOT, both FLAG_ONE_SHOT and FLAG_NO_CREATE need to be supplied.

Summary

Nested classes

Exception thrown when trying to send through a PendingIntent that has been canceled or is otherwise no longer able to execute the request.

abstract

Callback interface for discovering when a send operation has completed.

Constants
static Int

Flag indicating that the created PendingIntent with FLAG_MUTABLE is allowed to have an unsafe implicit Intent within.

static Int

Flag indicating that if the described PendingIntent already exists, the current one should be canceled before generating a new one.

static Int

Flag indicating that the created PendingIntent should be immutable.

static Int

Flag indicating that the created PendingIntent should be mutable.

static Int

Flag indicating that if the described PendingIntent does not already exist, then simply return null instead of creating it.

static Int

Flag indicating that this PendingIntent can be used only once.

static Int

Flag indicating that if the described PendingIntent already exists, then keep it but replace its extra data with what is in this new Intent.

Inherited constants
Public methods
Unit

Cancel a currently active PendingIntent.

Int

Boolean
equals(other: Any?)

Comparison operator on two PendingIntent objects, such that true is returned then they both represent the same operation from the same package.

static PendingIntent!
getActivities(context: Context!, requestCode: Int, intents: Array<Intent!>, flags: Int)

Like getActivity(android.content.Context,int,android.content.Intent,int), but allows an array of Intents to be supplied.

static PendingIntent!
getActivities(context: Context!, requestCode: Int, intents: Array<Intent!>, flags: Int, options: Bundle?)

Like getActivity(android.content.Context,int,android.content.Intent,int), but allows an array of Intents to be supplied.

static PendingIntent!
getActivity(context: Context!, requestCode: Int, intent: Intent!, flags: Int)

Retrieve a PendingIntent that will start a new activity, like calling Context.startActivity(Intent).

static PendingIntent!
getActivity(context: Context!, requestCode: Int, intent: Intent, flags: Int, options: Bundle?)

Retrieve a PendingIntent that will start a new activity, like calling Context.startActivity(Intent).

static PendingIntent!
getBroadcast(context: Context!, requestCode: Int, intent: Intent, flags: Int)

Retrieve a PendingIntent that will perform a broadcast, like calling Context.sendBroadcast().

String?

Return the package name of the application that created this PendingIntent, that is the identity under which you will actually be sending the Intent.

Int

Return the uid of the application that created this PendingIntent, that is the identity under which you will actually be sending the Intent.

UserHandle

Return the user handle of the application that created this PendingIntent, that is the user under which you will actually be sending the Intent.

static PendingIntent!
getForegroundService(context: Context!, requestCode: Int, intent: Intent, flags: Int)

Retrieve a PendingIntent that will start a foreground service, like calling Context.startForegroundService().

IntentSender

Retrieve a IntentSender object that wraps the existing sender of the PendingIntent

static PendingIntent!
getService(context: Context!, requestCode: Int, intent: Intent, flags: Int)

Retrieve a PendingIntent that will start a service, like calling Context.startService().

String?

Int

Boolean

Boolean

Boolean

Boolean

Check if this PendingIntent is marked with FLAG_IMMUTABLE.

Boolean

static PendingIntent?

Convenience function for reading either a PendingIntent or null pointer from a Parcel.

Unit

Perform the operation associated with this PendingIntent.

Unit
send(context: Context!, code: Int, intent: Intent?)

Perform the operation associated with this PendingIntent, allowing the caller to specify information about the Intent to use.

Unit
send(context: Context!, code: Int, intent: Intent?, onFinished: PendingIntent.OnFinished?, handler: Handler?)

Perform the operation associated with this PendingIntent, allowing the caller to specify information about the Intent to use and be notified when the send has completed.

Unit
send(context: Context!, code: Int, intent: Intent?, onFinished: PendingIntent.OnFinished?, handler: Handler?, requiredPermission: String?)

Perform the operation associated with this PendingIntent, allowing the caller to specify information about the Intent to use and be notified when the send has completed.

Unit
send(context: Context!, code: Int, intent: Intent?, onFinished: PendingIntent.OnFinished?, handler: Handler?, requiredPermission: String?, options: Bundle?)

Perform the operation associated with this PendingIntent, allowing the caller to specify information about the Intent to use and be notified when the send has completed.

Unit
send(options: Bundle?)

Perform the operation associated with this PendingIntent, supplying additional options for the operation.

Unit
send(code: Int)

Perform the operation associated with this PendingIntent.

Unit
send(code: Int, onFinished: PendingIntent.OnFinished?, handler: Handler?)

Perform the operation associated with this PendingIntent, allowing the caller to be notified when the send has completed.

String

static Unit

Convenience function for writing either a PendingIntent or null pointer to a Parcel.

Unit
writeToParcel(out: Parcel, flags: Int)

Properties
static Parcelable.Creator<PendingIntent!>

Constants

FLAG_ALLOW_UNSAFE_IMPLICIT_INTENT

Added in API level 34
static val FLAG_ALLOW_UNSAFE_IMPLICIT_INTENT: Int

Flag indicating that the created PendingIntent with FLAG_MUTABLE is allowed to have an unsafe implicit Intent within.

Starting with android.os.Build.VERSION_CODES#UPSIDE_DOWN_CAKE, for apps that target SDK android.os.Build.VERSION_CODES#UPSIDE_DOWN_CAKE or higher, creation of a PendingIntent with FLAG_MUTABLE and an implicit Intent within will throw an IllegalArgumentException for security reasons. To bypass this check, use FLAG_ALLOW_UNSAFE_IMPLICIT_INTENT when creating a PendingIntent. However, it is strongly recommended to not to use this flag and make the Intent explicit or the PendingIntent immutable, thereby making the Intent safe.

Value: 16777216

FLAG_CANCEL_CURRENT

Added in API level 1
static val FLAG_CANCEL_CURRENT: Int

Flag indicating that if the described PendingIntent already exists, the current one should be canceled before generating a new one. For use with #getActivity, getBroadcast, and getService.

You can use this to retrieve a new PendingIntent when you are only changing the extra data in the Intent; by canceling the previous pending intent, this ensures that only entities given the new data will be able to launch it. If this assurance is not an issue, consider FLAG_UPDATE_CURRENT.

Value: 268435456

FLAG_IMMUTABLE

Added in API level 23
static val FLAG_IMMUTABLE: Int

Flag indicating that the created PendingIntent should be immutable. This means that the additional intent argument passed to the send methods to fill in unpopulated properties of this intent will be ignored.

FLAG_IMMUTABLE only limits the ability to alter the semantics of the intent that is sent by #send by the invoker of #send. The creator of the PendingIntent can always update the PendingIntent itself via FLAG_UPDATE_CURRENT.

Value: 67108864

FLAG_MUTABLE

Added in API level 31
static val FLAG_MUTABLE: Int

Flag indicating that the created PendingIntent should be mutable. This flag cannot be combined with FLAG_IMMUTABLE.

Up until android.os.Build.VERSION_CODES#R, PendingIntents are assumed to be mutable by default, unless FLAG_IMMUTABLE is set. Starting with android.os.Build.VERSION_CODES#S, it will be required to explicitly specify the mutability of PendingIntents on creation with either FLAG_IMMUTABLE or FLAG_MUTABLE. It is strongly recommended to use FLAG_IMMUTABLE when creating a PendingIntent. FLAG_MUTABLE should only be used when some functionality relies on modifying the underlying intent, e.g. any PendingIntent that needs to be used with inline reply or bubbles.

Value: 33554432

FLAG_NO_CREATE

Added in API level 1
static val FLAG_NO_CREATE: Int

Flag indicating that if the described PendingIntent does not already exist, then simply return null instead of creating it. For use with #getActivity, getBroadcast, and getService.

Value: 536870912

FLAG_ONE_SHOT

Added in API level 1
static val FLAG_ONE_SHOT: Int

Flag indicating that this PendingIntent can be used only once. For use with #getActivity, getBroadcast, and getService.

If set, after send() is called on it, it will be automatically canceled for you and any future attempt to send through it will fail.

Value: 1073741824

FLAG_UPDATE_CURRENT

Added in API level 3
static val FLAG_UPDATE_CURRENT: Int

Flag indicating that if the described PendingIntent already exists, then keep it but replace its extra data with what is in this new Intent. For use with #getActivity, getBroadcast, and getService.

This can be used if you are creating intents where only the extras change, and don't care that any entities that received your previous PendingIntent will be able to launch it with your new extras even if they are not explicitly given to it.

FLAG_UPDATE_CURRENT still works even if FLAG_IMMUTABLE is set - the creator of the PendingIntent can always update the PendingIntent itself. The IMMUTABLE flag only limits the ability to alter the semantics of the intent that is sent by #send by the invoker of #send.

Value: 134217728

Public methods

cancel

Added in API level 1
fun cancel(): Unit

Cancel a currently active PendingIntent. Only the original application owning a PendingIntent can cancel it.

describeContents

Added in API level 1
fun describeContents(): Int
Return
Int a bitmask indicating the set of special object types marshaled by this Parcelable object instance. Value is either 0 or android.os.Parcelable#CONTENTS_FILE_DESCRIPTOR

equals

Added in API level 1
fun equals(other: Any?): Boolean

Comparison operator on two PendingIntent objects, such that true is returned then they both represent the same operation from the same package. This allows you to use #getActivity, getBroadcast, or getService multiple times (even across a process being killed), resulting in different PendingIntent objects but whose equals() method identifies them as being the same operation.

Parameters
obj the reference object with which to compare.
otherObj This value may be null.
Return
Boolean true if this object is the same as the obj argument; false otherwise.

getActivities

Added in API level 11
static fun getActivities(
    context: Context!,
    requestCode: Int,
    intents: Array<Intent!>,
    flags: Int
): PendingIntent!

Like getActivity(android.content.Context,int,android.content.Intent,int), but allows an array of Intents to be supplied. The last Intent in the array is taken as the primary key for the PendingIntent, like the single Intent given to getActivity(android.content.Context,int,android.content.Intent,int). Upon sending the resulting PendingIntent, all of the Intents are started in the same way as they would be by passing them to Context.startActivities(Intent[]).

The first intent in the array will be started outside of the context of an existing activity, so you must use the Intent.FLAG_ACTIVITY_NEW_TASK launch flag in the Intent. (Activities after the first in the array are started in the context of the previous activity in the array, so FLAG_ACTIVITY_NEW_TASK is not needed nor desired for them.)

The last intent in the array represents the key for the PendingIntent. In other words, it is the significant element for matching (as done with the single intent given to getActivity(android.content.Context,int,android.content.Intent,int), its content will be the subject of replacement by send(android.content.Context,int,android.content.Intent) and FLAG_UPDATE_CURRENT, etc. This is because it is the most specific of the supplied intents, and the UI the user actually sees when the intents are started.

For security reasons, the android.content.Intent objects you supply here should almost always be explicit intents, that is specify an explicit component to be delivered to through Intent.setClass

Parameters
context Context!: The Context in which this PendingIntent should start the activity.
requestCode Int: Private request code for the sender
intents Array<Intent!>: Array of Intents of the activities to be launched. This value cannot be null.
flags Int: May be FLAG_ONE_SHOT, FLAG_NO_CREATE, FLAG_CANCEL_CURRENT, FLAG_UPDATE_CURRENT, or any of the flags as supported by Intent.fillIn() to control which unspecified parts of the intent that can be supplied when the actual send happens. Value is either 0 or a combination of android.app.PendingIntent#FLAG_ONE_SHOT, android.app.PendingIntent#FLAG_NO_CREATE, android.app.PendingIntent#FLAG_CANCEL_CURRENT, android.app.PendingIntent#FLAG_UPDATE_CURRENT, android.app.PendingIntent#FLAG_IMMUTABLE, android.app.PendingIntent#FLAG_MUTABLE, android.app.PendingIntent.FLAG_MUTABLE_UNAUDITED, android.app.PendingIntent#FLAG_ALLOW_UNSAFE_IMPLICIT_INTENT, android.content.Intent#FILL_IN_ACTION, android.content.Intent#FILL_IN_DATA, android.content.Intent#FILL_IN_CATEGORIES, android.content.Intent#FILL_IN_COMPONENT, android.content.Intent#FILL_IN_PACKAGE, android.content.Intent#FILL_IN_SOURCE_BOUNDS, android.content.Intent#FILL_IN_SELECTOR, and android.content.Intent#FILL_IN_CLIP_DATA
Return
PendingIntent! Returns an existing or new PendingIntent matching the given parameters. May return null only if FLAG_NO_CREATE has been supplied.

getActivities

Added in API level 16
static fun getActivities(
    context: Context!,
    requestCode: Int,
    intents: Array<Intent!>,
    flags: Int,
    options: Bundle?
): PendingIntent!

Like getActivity(android.content.Context,int,android.content.Intent,int), but allows an array of Intents to be supplied. The last Intent in the array is taken as the primary key for the PendingIntent, like the single Intent given to getActivity(android.content.Context,int,android.content.Intent,int). Upon sending the resulting PendingIntent, all of the Intents are started in the same way as they would be by passing them to Context.startActivities(Intent[]).

The first intent in the array will be started outside of the context of an existing activity, so you must use the Intent.FLAG_ACTIVITY_NEW_TASK launch flag in the Intent. (Activities after the first in the array are started in the context of the previous activity in the array, so FLAG_ACTIVITY_NEW_TASK is not needed nor desired for them.)

The last intent in the array represents the key for the PendingIntent. In other words, it is the significant element for matching (as done with the single intent given to getActivity(android.content.Context,int,android.content.Intent,int), its content will be the subject of replacement by send(android.content.Context,int,android.content.Intent) and FLAG_UPDATE_CURRENT, etc. This is because it is the most specific of the supplied intents, and the UI the user actually sees when the intents are started.

For security reasons, the android.content.Intent objects you supply here should almost always be explicit intents, that is specify an explicit component to be delivered to through Intent.setClass

Parameters
context Context!: The Context in which this PendingIntent should start the activity.
requestCode Int: Private request code for the sender
intents Array<Intent!>: Array of Intents of the activities to be launched. This value cannot be null.
flags Int: May be FLAG_ONE_SHOT, FLAG_NO_CREATE, FLAG_CANCEL_CURRENT, FLAG_UPDATE_CURRENT, FLAG_IMMUTABLE or any of the flags as supported by Intent.fillIn() to control which unspecified parts of the intent that can be supplied when the actual send happens. Value is either 0 or a combination of android.app.PendingIntent#FLAG_ONE_SHOT, android.app.PendingIntent#FLAG_NO_CREATE, android.app.PendingIntent#FLAG_CANCEL_CURRENT, android.app.PendingIntent#FLAG_UPDATE_CURRENT, android.app.PendingIntent#FLAG_IMMUTABLE, android.app.PendingIntent#FLAG_MUTABLE, android.app.PendingIntent.FLAG_MUTABLE_UNAUDITED, android.app.PendingIntent#FLAG_ALLOW_UNSAFE_IMPLICIT_INTENT, android.content.Intent#FILL_IN_ACTION, android.content.Intent#FILL_IN_DATA, android.content.Intent#FILL_IN_CATEGORIES, android.content.Intent#FILL_IN_COMPONENT, android.content.Intent#FILL_IN_PACKAGE, android.content.Intent#FILL_IN_SOURCE_BOUNDS, android.content.Intent#FILL_IN_SELECTOR, and android.content.Intent#FILL_IN_CLIP_DATA
options Bundle?: This value may be null.
Return
PendingIntent! Returns an existing or new PendingIntent matching the given parameters. May return null only if FLAG_NO_CREATE has been supplied.

getActivity

Added in API level 1
static fun getActivity(
    context: Context!,
    requestCode: Int,
    intent: Intent!,
    flags: Int
): PendingIntent!

Retrieve a PendingIntent that will start a new activity, like calling Context.startActivity(Intent). Note that the activity will be started outside of the context of an existing activity, so you must use the Intent.FLAG_ACTIVITY_NEW_TASK launch flag in the Intent.

For security reasons, the android.content.Intent you supply here should almost always be an explicit intent, that is specify an explicit component to be delivered to through Intent.setClass

Parameters
context Context!: The Context in which this PendingIntent should start the activity.
requestCode Int: Private request code for the sender
intent Intent!: Intent of the activity to be launched.
flags Int: May be FLAG_ONE_SHOT, FLAG_NO_CREATE, FLAG_CANCEL_CURRENT, FLAG_UPDATE_CURRENT, or any of the flags as supported by Intent.fillIn() to control which unspecified parts of the intent that can be supplied when the actual send happens. Value is either 0 or a combination of android.app.PendingIntent#FLAG_ONE_SHOT, android.app.PendingIntent#FLAG_NO_CREATE, android.app.PendingIntent#FLAG_CANCEL_CURRENT, android.app.PendingIntent#FLAG_UPDATE_CURRENT, android.app.PendingIntent#FLAG_IMMUTABLE, android.app.PendingIntent#FLAG_MUTABLE, android.app.PendingIntent.FLAG_MUTABLE_UNAUDITED, android.app.PendingIntent#FLAG_ALLOW_UNSAFE_IMPLICIT_INTENT, android.content.Intent#FILL_IN_ACTION, android.content.Intent#FILL_IN_DATA, android.content.Intent#FILL_IN_CATEGORIES, android.content.Intent#FILL_IN_COMPONENT, android.content.Intent#FILL_IN_PACKAGE, android.content.Intent#FILL_IN_SOURCE_BOUNDS, android.content.Intent#FILL_IN_SELECTOR, and android.content.Intent#FILL_IN_CLIP_DATA
Return
PendingIntent! Returns an existing or new PendingIntent matching the given parameters. May return null only if FLAG_NO_CREATE has been supplied.

getActivity

Added in API level 16
static fun getActivity(
    context: Context!,
    requestCode: Int,
    intent: Intent,
    flags: Int,
    options: Bundle?
): PendingIntent!

Retrieve a PendingIntent that will start a new activity, like calling Context.startActivity(Intent). Note that the activity will be started outside of the context of an existing activity, so you must use the Intent.FLAG_ACTIVITY_NEW_TASK launch flag in the Intent.

For security reasons, the android.content.Intent you supply here should almost always be an explicit intent, that is specify an explicit component to be delivered to through Intent.setClass

Parameters
context Context!: The Context in which this PendingIntent should start the activity.
requestCode Int: Private request code for the sender
intent Intent: Intent of the activity to be launched. This value cannot be null.
flags Int: May be FLAG_ONE_SHOT, FLAG_NO_CREATE, FLAG_CANCEL_CURRENT, FLAG_UPDATE_CURRENT, or any of the flags as supported by Intent.fillIn() to control which unspecified parts of the intent that can be supplied when the actual send happens. Value is either 0 or a combination of android.app.PendingIntent#FLAG_ONE_SHOT, android.app.PendingIntent#FLAG_NO_CREATE, android.app.PendingIntent#FLAG_CANCEL_CURRENT, android.app.PendingIntent#FLAG_UPDATE_CURRENT, android.app.PendingIntent#FLAG_IMMUTABLE, android.app.PendingIntent#FLAG_MUTABLE, android.app.PendingIntent.FLAG_MUTABLE_UNAUDITED, android.app.PendingIntent#FLAG_ALLOW_UNSAFE_IMPLICIT_INTENT, android.content.Intent#FILL_IN_ACTION, android.content.Intent#FILL_IN_DATA, android.content.Intent#FILL_IN_CATEGORIES, android.content.Intent#FILL_IN_COMPONENT, android.content.Intent#FILL_IN_PACKAGE, android.content.Intent#FILL_IN_SOURCE_BOUNDS, android.content.Intent#FILL_IN_SELECTOR, and android.content.Intent#FILL_IN_CLIP_DATA
options Bundle?: Additional options for how the Activity should be started. May be null if there are no options.
Return
PendingIntent! Returns an existing or new PendingIntent matching the given parameters. May return null only if FLAG_NO_CREATE has been supplied.

getBroadcast

Added in API level 1
static fun getBroadcast(
    context: Context!,
    requestCode: Int,
    intent: Intent,
    flags: Int
): PendingIntent!

Retrieve a PendingIntent that will perform a broadcast, like calling Context.sendBroadcast().

For security reasons, the android.content.Intent you supply here should almost always be an explicit intent, that is specify an explicit component to be delivered to through Intent.setClass

Parameters
context Context!: The Context in which this PendingIntent should perform the broadcast.
requestCode Int: Private request code for the sender
intent Intent: The Intent to be broadcast. This value cannot be null.
flags Int: May be FLAG_ONE_SHOT, FLAG_NO_CREATE, FLAG_CANCEL_CURRENT, FLAG_UPDATE_CURRENT, FLAG_IMMUTABLE or any of the flags as supported by Intent.fillIn() to control which unspecified parts of the intent that can be supplied when the actual send happens. Value is either 0 or a combination of android.app.PendingIntent#FLAG_ONE_SHOT, android.app.PendingIntent#FLAG_NO_CREATE, android.app.PendingIntent#FLAG_CANCEL_CURRENT, android.app.PendingIntent#FLAG_UPDATE_CURRENT, android.app.PendingIntent#FLAG_IMMUTABLE, android.app.PendingIntent#FLAG_MUTABLE, android.app.PendingIntent.FLAG_MUTABLE_UNAUDITED, android.app.PendingIntent#FLAG_ALLOW_UNSAFE_IMPLICIT_INTENT, android.content.Intent#FILL_IN_ACTION, android.content.Intent#FILL_IN_DATA, android.content.Intent#FILL_IN_CATEGORIES, android.content.Intent#FILL_IN_COMPONENT, android.content.Intent#FILL_IN_PACKAGE, android.content.Intent#FILL_IN_SOURCE_BOUNDS, android.content.Intent#FILL_IN_SELECTOR, and android.content.Intent#FILL_IN_CLIP_DATA
Return
PendingIntent! Returns an existing or new PendingIntent matching the given parameters. May return null only if FLAG_NO_CREATE has been supplied.

getCreatorPackage

Added in API level 17
fun getCreatorPackage(): String?

Return the package name of the application that created this PendingIntent, that is the identity under which you will actually be sending the Intent. The returned string is supplied by the system, so that an application can not spoof its package.

Be careful about how you use this. All this tells you is who created the PendingIntent. It does not tell you who handed the PendingIntent to you: that is, PendingIntent objects are intended to be passed between applications, so the PendingIntent you receive from an application could actually be one it received from another application, meaning the result you get here will identify the original application. Because of this, you should only use this information to identify who you expect to be interacting with through a #send call, not who gave you the PendingIntent.

Return
String? The package name of the PendingIntent. This value may be null.

getCreatorUid

Added in API level 17
fun getCreatorUid(): Int

Return the uid of the application that created this PendingIntent, that is the identity under which you will actually be sending the Intent. The returned integer is supplied by the system, so that an application can not spoof its uid.

Be careful about how you use this. All this tells you is who created the PendingIntent. It does not tell you who handed the PendingIntent to you: that is, PendingIntent objects are intended to be passed between applications, so the PendingIntent you receive from an application could actually be one it received from another application, meaning the result you get here will identify the original application. Because of this, you should only use this information to identify who you expect to be interacting with through a #send call, not who gave you the PendingIntent.

Return
Int The uid of the PendingIntent, or -1 if there is none associated with it.

getCreatorUserHandle

Added in API level 17
fun getCreatorUserHandle(): UserHandle

Return the user handle of the application that created this PendingIntent, that is the user under which you will actually be sending the Intent. The returned UserHandle is supplied by the system, so that an application can not spoof its user. See Process.myUserHandle() for more explanation of user handles.

Be careful about how you use this. All this tells you is who created the PendingIntent. It does not tell you who handed the PendingIntent to you: that is, PendingIntent objects are intended to be passed between applications, so the PendingIntent you receive from an application could actually be one it received from another application, meaning the result you get here will identify the original application. Because of this, you should only use this information to identify who you expect to be interacting with through a #send call, not who gave you the PendingIntent.

Return
UserHandle The user handle of the PendingIntent This value cannot be null.

getForegroundService

Added in API level 26
static fun getForegroundService(
    context: Context!,
    requestCode: Int,
    intent: Intent,
    flags: Int
): PendingIntent!

Retrieve a PendingIntent that will start a foreground service, like calling Context.startForegroundService(). The start arguments given to the service will come from the extras of the Intent.

For security reasons, the android.content.Intent you supply here should almost always be an explicit intent, that is specify an explicit component to be delivered to through Intent.setClass

Parameters
context Context!: The Context in which this PendingIntent should start the service.
requestCode Int: Private request code for the sender
intent Intent: An Intent describing the service to be started. This value cannot be null.
flags Int: May be FLAG_ONE_SHOT, FLAG_NO_CREATE, FLAG_CANCEL_CURRENT, FLAG_UPDATE_CURRENT, FLAG_IMMUTABLE or any of the flags as supported by Intent.fillIn() to control which unspecified parts of the intent that can be supplied when the actual send happens. Value is either 0 or a combination of android.app.PendingIntent#FLAG_ONE_SHOT, android.app.PendingIntent#FLAG_NO_CREATE, android.app.PendingIntent#FLAG_CANCEL_CURRENT, android.app.PendingIntent#FLAG_UPDATE_CURRENT, android.app.PendingIntent#FLAG_IMMUTABLE, android.app.PendingIntent#FLAG_MUTABLE, android.app.PendingIntent.FLAG_MUTABLE_UNAUDITED, android.app.PendingIntent#FLAG_ALLOW_UNSAFE_IMPLICIT_INTENT, android.content.Intent#FILL_IN_ACTION, android.content.Intent#FILL_IN_DATA, android.content.Intent#FILL_IN_CATEGORIES, android.content.Intent#FILL_IN_COMPONENT, android.content.Intent#FILL_IN_PACKAGE, android.content.Intent#FILL_IN_SOURCE_BOUNDS, android.content.Intent#FILL_IN_SELECTOR, and android.content.Intent#FILL_IN_CLIP_DATA
Return
PendingIntent! Returns an existing or new PendingIntent matching the given parameters. May return null only if FLAG_NO_CREATE has been supplied.

getIntentSender

Added in API level 4
fun getIntentSender(): IntentSender

Retrieve a IntentSender object that wraps the existing sender of the PendingIntent

Return
IntentSender Returns a IntentSender object that wraps the sender of PendingIntent This value cannot be null.

getService

Added in API level 1
static fun getService(
    context: Context!,
    requestCode: Int,
    intent: Intent,
    flags: Int
): PendingIntent!

Retrieve a PendingIntent that will start a service, like calling Context.startService(). The start arguments given to the service will come from the extras of the Intent.

For security reasons, the android.content.Intent you supply here should almost always be an explicit intent, that is specify an explicit component to be delivered to through Intent.setClass

Parameters
context Context!: The Context in which this PendingIntent should start the service.
requestCode Int: Private request code for the sender
intent Intent: An Intent describing the service to be started. This value cannot be null.
flags Int: May be FLAG_ONE_SHOT, FLAG_NO_CREATE, FLAG_CANCEL_CURRENT, FLAG_UPDATE_CURRENT, FLAG_IMMUTABLE or any of the flags as supported by Intent.fillIn() to control which unspecified parts of the intent that can be supplied when the actual send happens. Value is either 0 or a combination of android.app.PendingIntent#FLAG_ONE_SHOT, android.app.PendingIntent#FLAG_NO_CREATE, android.app.PendingIntent#FLAG_CANCEL_CURRENT, android.app.PendingIntent#FLAG_UPDATE_CURRENT, android.app.PendingIntent#FLAG_IMMUTABLE, android.app.PendingIntent#FLAG_MUTABLE, android.app.PendingIntent.FLAG_MUTABLE_UNAUDITED, android.app.PendingIntent#FLAG_ALLOW_UNSAFE_IMPLICIT_INTENT, android.content.Intent#FILL_IN_ACTION, android.content.Intent#FILL_IN_DATA, android.content.Intent#FILL_IN_CATEGORIES, android.content.Intent#FILL_IN_COMPONENT, android.content.Intent#FILL_IN_PACKAGE, android.content.Intent#FILL_IN_SOURCE_BOUNDS, android.content.Intent#FILL_IN_SELECTOR, and android.content.Intent#FILL_IN_CLIP_DATA
Return
PendingIntent! Returns an existing or new PendingIntent matching the given parameters. May return null only if FLAG_NO_CREATE has been supplied.

getTargetPackage

Added in API level 1
Deprecated in API level 17
fun getTargetPackage(): String?

Deprecated: Renamed to getCreatorPackage().

Return
String? This value may be null.

hashCode

Added in API level 1
fun hashCode(): Int
Return
Int a hash code value for this object.

isActivity

Added in API level 31
fun isActivity(): Boolean
Return
Boolean TRUE if this PendingIntent was created with #getActivity or #getActivities.

isBroadcast

Added in API level 31
fun isBroadcast(): Boolean
Return
Boolean TRUE if this PendingIntent was created with getBroadcast.

isForegroundService

Added in API level 31
fun isForegroundService(): Boolean
Return
Boolean TRUE if this PendingIntent was created with getForegroundService.

isImmutable

Added in API level 31
fun isImmutable(): Boolean

Check if this PendingIntent is marked with FLAG_IMMUTABLE.

isService

Added in API level 31
fun isService(): Boolean
Return
Boolean TRUE if this PendingIntent was created with getService.

readPendingIntentOrNullFromParcel

Added in API level 1
static fun readPendingIntentOrNullFromParcel(in: Parcel): PendingIntent?

Convenience function for reading either a PendingIntent or null pointer from a Parcel. You must have previously written the PendingIntent with writePendingIntentOrNullToParcel.

Parameters
in Parcel: The Parcel containing the written PendingIntent. This value cannot be null.
Return
PendingIntent? Returns the PendingIntent read from the Parcel, or null if null had been written.

send

Added in API level 1
fun send(): Unit

Perform the operation associated with this PendingIntent.

Exceptions
android.app.PendingIntent.CanceledException Throws CanceledException if the PendingIntent is no longer allowing more intents to be sent through it.

send

Added in API level 1
fun send(
    context: Context!,
    code: Int,
    intent: Intent?
): Unit

Perform the operation associated with this PendingIntent, allowing the caller to specify information about the Intent to use.

Parameters
context Context!: The Context of the caller.
code Int: Result code to supply back to the PendingIntent's target.
intent Intent?: Additional Intent data. See Intent.fillIn() for information on how this is applied to the original Intent. If flag FLAG_IMMUTABLE was set when this pending intent was created, this argument will be ignored. This value may be null.
Exceptions
android.app.PendingIntent.CanceledException Throws CanceledException if the PendingIntent is no longer allowing more intents to be sent through it.

send

Added in API level 1
fun send(
    context: Context!,
    code: Int,
    intent: Intent?,
    onFinished: PendingIntent.OnFinished?,
    handler: Handler?
): Unit

Perform the operation associated with this PendingIntent, allowing the caller to specify information about the Intent to use and be notified when the send has completed.

For the intent parameter, a PendingIntent often has restrictions on which fields can be supplied here, based on how the PendingIntent was retrieved in #getActivity, getBroadcast, or getService.

Parameters
context Context!: The Context of the caller. This may be null if intent is also null.
code Int: Result code to supply back to the PendingIntent's target.
intent Intent?: Additional Intent data. See Intent.fillIn() for information on how this is applied to the original Intent. Use null to not modify the original Intent. If flag FLAG_IMMUTABLE was set when this pending intent was created, this argument will be ignored.
onFinished PendingIntent.OnFinished?: The object to call back on when the send has completed, or null for no callback.
handler Handler?: Handler identifying the thread on which the callback should happen. If null, the callback will happen from the thread pool of the process.
Exceptions
android.app.PendingIntent.CanceledException Throws CanceledException if the PendingIntent is no longer allowing more intents to be sent through it.

send

Added in API level 14
fun send(
    context: Context!,
    code: Int,
    intent: Intent?,
    onFinished: PendingIntent.OnFinished?,
    handler: Handler?,
    requiredPermission: String?
): Unit

Perform the operation associated with this PendingIntent, allowing the caller to specify information about the Intent to use and be notified when the send has completed.

For the intent parameter, a PendingIntent often has restrictions on which fields can be supplied here, based on how the PendingIntent was retrieved in #getActivity, getBroadcast, or getService.

Parameters
context Context!: The Context of the caller. This may be null if intent is also null.
code Int: Result code to supply back to the PendingIntent's target.
intent Intent?: Additional Intent data. See Intent.fillIn() for information on how this is applied to the original Intent. Use null to not modify the original Intent. If flag FLAG_IMMUTABLE was set when this pending intent was created, this argument will be ignored.
onFinished PendingIntent.OnFinished?: The object to call back on when the send has completed, or null for no callback.
handler Handler?: Handler identifying the thread on which the callback should happen. If null, the callback will happen from the thread pool of the process.
requiredPermission String?: Name of permission that a recipient of the PendingIntent is required to hold. This is only valid for broadcast intents, and corresponds to the permission argument in Context.sendOrderedBroadcast(Intent, String). If null, no permission is required.
Exceptions
android.app.PendingIntent.CanceledException Throws CanceledException if the PendingIntent is no longer allowing more intents to be sent through it.

send

Added in API level 23
fun send(
    context: Context!,
    code: Int,
    intent: Intent?,
    onFinished: PendingIntent.OnFinished?,
    handler: Handler?,
    requiredPermission: String?,
    options: Bundle?
): Unit

Perform the operation associated with this PendingIntent, allowing the caller to specify information about the Intent to use and be notified when the send has completed.

For the intent parameter, a PendingIntent often has restrictions on which fields can be supplied here, based on how the PendingIntent was retrieved in #getActivity, getBroadcast, or getService.

Parameters
context Context!: The Context of the caller. This may be null if intent is also null.
code Int: Result code to supply back to the PendingIntent's target.
intent Intent?: Additional Intent data. See Intent.fillIn() for information on how this is applied to the original Intent. Use null to not modify the original Intent. If flag FLAG_IMMUTABLE was set when this pending intent was created, this argument will be ignored.
onFinished PendingIntent.OnFinished?: The object to call back on when the send has completed, or null for no callback.
handler Handler?: Handler identifying the thread on which the callback should happen. If null, the callback will happen from the thread pool of the process.
requiredPermission String?: Name of permission that a recipient of the PendingIntent is required to hold. This is only valid for broadcast intents, and corresponds to the permission argument in Context.sendOrderedBroadcast(Intent, String). If null, no permission is required.
options Bundle?: Additional options the caller would like to provide to modify the sending behavior. May be built from an ActivityOptions to apply to an activity start. This value may be null.
Exceptions
android.app.PendingIntent.CanceledException Throws CanceledException if the PendingIntent is no longer allowing more intents to be sent through it.

send

Added in API level 34
fun send(options: Bundle?): Unit

Perform the operation associated with this PendingIntent, supplying additional options for the operation.

Parameters
options Bundle?: Additional options the caller would like to provide to modify the sending behavior. May be built from an ActivityOptions to apply to an activity start. This value may be null.
Exceptions
android.app.PendingIntent.CanceledException Throws CanceledException if the PendingIntent is no longer allowing more intents to be sent through it.

send

Added in API level 1
fun send(code: Int): Unit

Perform the operation associated with this PendingIntent.

Parameters
code Int: Result code to supply back to the PendingIntent's target.
Exceptions
android.app.PendingIntent.CanceledException Throws CanceledException if the PendingIntent is no longer allowing more intents to be sent through it.

send

Added in API level 1
fun send(
    code: Int,
    onFinished: PendingIntent.OnFinished?,
    handler: Handler?
): Unit

Perform the operation associated with this PendingIntent, allowing the caller to be notified when the send has completed.

Parameters
code Int: Result code to supply back to the PendingIntent's target.
onFinished PendingIntent.OnFinished?: The object to call back on when the send has completed, or null for no callback.
handler Handler?: Handler identifying the thread on which the callback should happen. If null, the callback will happen from the thread pool of the process.
Exceptions
android.app.PendingIntent.CanceledException Throws CanceledException if the PendingIntent is no longer allowing more intents to be sent through it.

toString

Added in API level 1
fun toString(): String
Return
String a string representation of the object.

writePendingIntentOrNullToParcel

Added in API level 1
static fun writePendingIntentOrNullToParcel(
    sender: PendingIntent?,
    out: Parcel
): Unit

Convenience function for writing either a PendingIntent or null pointer to a Parcel. You must use this with readPendingIntentOrNullFromParcel for later reading it.

Parameters
sender PendingIntent?: The PendingIntent to write, or null.
out Parcel: Where to write the PendingIntent. This value cannot be null.

writeToParcel

Added in API level 1
fun writeToParcel(
    out: Parcel,
    flags: Int
): Unit
Parameters
dest The Parcel in which the object should be written. This value cannot be null.
flags Int: Additional flags about how the object should be written. May be 0 or PARCELABLE_WRITE_RETURN_VALUE. Value is either 0 or a combination of android.os.Parcelable#PARCELABLE_WRITE_RETURN_VALUE, and android.os.Parcelable.PARCELABLE_ELIDE_DUPLICATES

Properties

CREATOR

Added in API level 1
static val CREATOR: Parcelable.Creator<PendingIntent!>