CarPendingIntent

public final class CarPendingIntent
extends Object

java.lang.Object
   ↳ androidx.car.app.notification.CarPendingIntent


A class which creates PendingIntents that will start a car app, to be used in a notification action.

Summary

Public methods

static PendingIntent getCarApp(Context context, int requestCode, Intent intent, int flags)

Creates a PendingIntent that can be sent in a notification action which will allow the targeted car app to be started when the user clicks on the action.

Inherited methods

Public methods

getCarApp

public static PendingIntent getCarApp (Context context, 
                int requestCode, 
                Intent intent, 
                int flags)

Creates a PendingIntent that can be sent in a notification action which will allow the targeted car app to be started when the user clicks on the action.

See CarContext.startCarApp(Intent) for the supported intents that can be passed to this method.

Here is an example of usage of this method when setting a notification's intent:

     NotificationCompat.Builder builder;
     ...
     builder.setContentIntent(CarPendingIntent.getCarApp(getCarContext(), 0,
             new Intent(Intent.ACTION_VIEW).setComponent(
                     new ComponentName(getCarContext(), MyCarAppService.class)), 0));
 

Parameters
context Context: the context in which this PendingIntent should use to start the car app

requestCode int: private request code for the sender

intent Intent: the intent that will be sent to the car app

flags int: may be any of the flags allowed by PendingIntent.getBroadcast(Context, int, Intent, int) except for PendingIntent.FLAG_IMMUTABLE as the PendingIntent needs to be mutable to allow the host to add the necessary extras for starting the car app. If PendingIntent.FLAG_IMMUTABLE is set, it will be unset before creating the PendingIntent

Returns
PendingIntent an existing or new PendingIntent matching the given parameters. May return null only if PendingIntent.FLAG_NO_CREATE has been supplied.

Throws
NullPointerException if either context or intent are null
InvalidParameterException if the intent is not for starting a navigation or a phone call and does not have the target car app's component name
SecurityException if the intent is for a different component than the one associated with the input context