# CarPendingIntent

Artifact: [androidx.car.app:app](https://developer.android.com/jetpack/androidx/releases/car-app) [View Source](https://cs.android.com/search?q=file:androidx/car/app/notification/CarPendingIntent.java+class:androidx.car.app.notification.CarPendingIntent) Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/car-app#1.1.0)

*** ** * ** ***

<br />

```
public final class CarPendingIntent
```

<br />

*** ** * ** ***

A class which creates `https://developer.android.com/reference/android/app/PendingIntent.html`s that will start a car app, to be used in a notification action.

## Summary

| ### Public methods |
|---|---|
| `static @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/app/PendingIntent.html` | `https://developer.android.com/reference/androidx/car/app/notification/CarPendingIntent#getCarApp(android.content.Context,int,android.content.Intent,int)( @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/content/Context.html context, int requestCode, @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/content/Intent.html intent, int flags )` Creates a `https://developer.android.com/reference/android/app/PendingIntent.html` 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](https://developer.android.com/jetpack/androidx/releases/car-app#1.1.0)

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

Creates a `https://developer.android.com/reference/android/app/PendingIntent.html` 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 `https://developer.android.com/reference/androidx/car/app/CarContext#startCarApp(android.content.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 |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/content/Context.html context` | the context in which this PendingIntent should use to start the car app |
| `int requestCode` | private request code for the sender |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/content/Intent.html intent` | the intent that will be sent to the car app |
| `int flags` | may be any of the flags allowed by `https://developer.android.com/reference/android/app/PendingIntent.html#getBroadcast(android.content.Context, int, android.content.Intent, int)` except for `https://developer.android.com/reference/android/app/PendingIntent.html#FLAG_IMMUTABLE` as the `https://developer.android.com/reference/android/app/PendingIntent.html` needs to be mutable to allow the host to add the necessary extras for starting the car app. If `https://developer.android.com/reference/android/app/PendingIntent.html#FLAG_IMMUTABLE` is set, it will be unset before creating the `https://developer.android.com/reference/android/app/PendingIntent.html` |

| Returns |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/app/PendingIntent.html` | an existing or new PendingIntent matching the given parameters. May return ` null` only if `https://developer.android.com/reference/android/app/PendingIntent.html#FLAG_NO_CREATE` has been supplied. |

| Throws |
|---|---|
| `https://developer.android.com/reference/java/lang/NullPointerException.html` | if either `context` or `intent` are null |
| `https://developer.android.com/reference/java/security/InvalidParameterException.html` | if the `intent` is not for starting a navigation or a phone call and does not have the target car app's component name |
| `https://developer.android.com/reference/java/lang/SecurityException.html` | if the `intent` is for a different component than the one associated with the input `context` |