CarNotificationManager

public final class CarNotificationManager


A manager for car apps to send notifications. This class wraps a NotificationManagerCompat to manage the actual sending of the Notification.

Summary

Public methods

boolean

Returns whether notifications from the calling package are not blocked.

void
cancel(int id)

Cancels a previously shown notification.

void
cancel(@Nullable String tag, int id)

Cancels a previously shown notification.

void

Cancels all previously shown notifications.

void

Creates a notification channel that notifications can be posted to.

void

Creates a group container for NotificationChannel objects.

void

Creates multiple notification channel groups.

void

Creates multiple notification channels that different notifications can be posted to.

void

Deletes the given notification channel.

void

Deletes the given notification channel group, and all notification channels that belong to it.

void

Deletes notification channels for which ids are NOT given.

static @NonNull CarNotificationManager
from(@NonNull Context context)

Returns a CarNotificationManager instance for a provided context.

static @NonNull Set<String>

Get the set of packages that have an enabled notification listener component within them.

int

Returns the user specified importance for notifications from the calling package.

@Nullable NotificationChannelCompat

Returns the notification channel settings for a given channel id.

@Nullable NotificationChannelCompat
getNotificationChannel(
    @NonNull String channelId,
    @NonNull String conversationId
)

Returns the notification channel settings for a given channel and conversation id.

@Nullable NotificationChannelGroupCompat

Returns the notification channel group settings for a given channel group id.

@NonNull List<NotificationChannelGroupCompat>

Returns all notification channel groups belonging to the calling app or an empty list on older SDKs which don't support Notification Channels.

@NonNull List<NotificationChannelCompat>

Returns all notification channels belonging to the calling app or an empty list on older SDKs which don't support Notification Channels.

void
notify(int id, @NonNull NotificationCompat.Builder notification)

Posts a notification.

void
notify(
    @Nullable String tag,
    int id,
    @NonNull NotificationCompat.Builder notification
)

Post a notification to be shown in the status bar, stream, etc.

Public methods

areNotificationsEnabled

Added in 1.1.0
public boolean areNotificationsEnabled()

Returns whether notifications from the calling package are not blocked.

cancel

Added in 1.1.0
public void cancel(int id)

Cancels a previously shown notification.

See also
cancel

cancel

Added in 1.1.0
public void cancel(@Nullable String tag, int id)

Cancels a previously shown notification.

See also
cancel

cancelAll

Added in 1.1.0
public void cancelAll()

Cancels all previously shown notifications.

See also
cancelAll

createNotificationChannel

Added in 1.1.0
public void createNotificationChannel(@NonNull NotificationChannelCompat channel)

Creates a notification channel that notifications can be posted to.

Throws
java.lang.NullPointerException

if channel is null

createNotificationChannelGroup

Added in 1.1.0
public void createNotificationChannelGroup(
    @NonNull NotificationChannelGroupCompat group
)

Creates a group container for NotificationChannel objects.

Throws
java.lang.NullPointerException

if group is null

createNotificationChannelGroups

Added in 1.1.0
public void createNotificationChannelGroups(
    @NonNull List<NotificationChannelGroupCompat> groups
)

Creates multiple notification channel groups. See createNotificationChannelGroup.

Throws
java.lang.NullPointerException

if groups is null

createNotificationChannels

Added in 1.1.0
public void createNotificationChannels(
    @NonNull List<NotificationChannelCompat> channels
)

Creates multiple notification channels that different notifications can be posted to. See createNotificationChannel.

Throws
java.lang.NullPointerException

if channels is null

deleteNotificationChannel

Added in 1.1.0
public void deleteNotificationChannel(@NonNull String channelId)

Deletes the given notification channel.

Throws
java.lang.NullPointerException

if channelId is null

deleteNotificationChannelGroup

Added in 1.1.0
public void deleteNotificationChannelGroup(@NonNull String groupId)

Deletes the given notification channel group, and all notification channels that belong to it.

Throws
java.lang.NullPointerException

if groupId is null

deleteUnlistedNotificationChannels

Added in 1.1.0
public void deleteUnlistedNotificationChannels(
    @NonNull Collection<String> channelIds
)

Deletes notification channels for which ids are NOT given.

Throws
java.lang.NullPointerException

if channelIds is null

from

Added in 1.1.0
public static @NonNull CarNotificationManager from(@NonNull Context context)

Returns a CarNotificationManager instance for a provided context.

Throws
java.lang.NullPointerException

if context is null

getEnabledListenerPackages

Added in 1.1.0
public static @NonNull Set<StringgetEnabledListenerPackages(@NonNull Context context)

Get the set of packages that have an enabled notification listener component within them.

Throws
java.lang.NullPointerException

if context is null

getImportance

Added in 1.1.0
public int getImportance()

Returns the user specified importance for notifications from the calling package.

See also
getImportance

getNotificationChannel

Added in 1.1.0
public @Nullable NotificationChannelCompat getNotificationChannel(@NonNull String channelId)

Returns the notification channel settings for a given channel id.

Throws
java.lang.NullPointerException

if channelId is null

getNotificationChannel

Added in 1.1.0
public @Nullable NotificationChannelCompat getNotificationChannel(
    @NonNull String channelId,
    @NonNull String conversationId
)

Returns the notification channel settings for a given channel and conversation id.

Throws
java.lang.NullPointerException

if either channelId of conversationId are null

getNotificationChannelGroup

Added in 1.1.0
public @Nullable NotificationChannelGroupCompat getNotificationChannelGroup(@NonNull String channelGroupId)

Returns the notification channel group settings for a given channel group id.

Throws
java.lang.NullPointerException

if channelGroupId is null

getNotificationChannelGroups

Added in 1.1.0
public @NonNull List<NotificationChannelGroupCompatgetNotificationChannelGroups()

Returns all notification channel groups belonging to the calling app or an empty list on older SDKs which don't support Notification Channels.

getNotificationChannels

Added in 1.1.0
public @NonNull List<NotificationChannelCompatgetNotificationChannels()

Returns all notification channels belonging to the calling app or an empty list on older SDKs which don't support Notification Channels.

notify

Added in 1.1.0
public void notify(int id, @NonNull NotificationCompat.Builder notification)

Posts a notification.

Callers are expected to extend the notification with CarAppExtender to ensure the notification will show up on all car environments. This method will extend the notification if it is not already extended for the car using a CarAppExtender.

Throws
java.lang.NullPointerException

if notification is null

See also
notify

notify

Added in 1.1.0
public void notify(
    @Nullable String tag,
    int id,
    @NonNull NotificationCompat.Builder notification
)

Post a notification to be shown in the status bar, stream, etc.

Callers are expected to extend the notification with CarAppExtender to ensure the notification will show up on all car environments. This method will extend the notification if it is not already extended for the car using a CarAppExtender.

Parameters
@Nullable String tag

the string identifier for a notification. Can be null.

int id

the ID of the notification. The pair (tag, id) must be unique within your app.

@NonNull NotificationCompat.Builder notification

the notification to post to the system

Throws
java.lang.NullPointerException

if notification is null