CarPendingIntent


public final class CarPendingIntent


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

Summary

Public methods

static @NonNull PendingIntent
getCarApp(
    @NonNull Context context,
    int requestCode,
    @NonNull 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.

Public methods

getCarApp

Added in 1.1.0
public static @NonNull PendingIntent getCarApp(
    @NonNull Context context,
    int requestCode,
    @NonNull 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 startCarApp 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
@NonNull Context context

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

int requestCode

private request code for the sender

@NonNull Intent intent

the intent that will be sent to the car app

int flags

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

Returns
@NonNull PendingIntent

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

Throws
java.lang.NullPointerException

if either context or intent are null

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

java.lang.SecurityException

if the intent is for a different component than the one associated with the input context