CarNotificationManager


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 functions

Boolean

Returns whether notifications from the calling package are not blocked.

Unit
cancel(id: Int)

Cancels a previously shown notification.

Unit
cancel(tag: String?, id: Int)

Cancels a previously shown notification.

Unit

Cancels all previously shown notifications.

Unit

Creates a notification channel that notifications can be posted to.

Unit

Creates a group container for NotificationChannel objects.

Unit

Creates multiple notification channel groups.

Unit

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

Unit

Deletes the given notification channel.

Unit

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

Unit

Deletes notification channels for which ids are NOT given.

java-static CarNotificationManager
from(context: Context)

Returns a CarNotificationManager instance for a provided context.

java-static (Mutable)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.

NotificationChannelCompat?

Returns the notification channel settings for a given channel id.

NotificationChannelCompat?
getNotificationChannel(channelId: String, conversationId: String)

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

NotificationChannelGroupCompat?

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

(Mutable)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.

(Mutable)List<NotificationChannelCompat!>

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

Unit
notify(id: Int, notification: NotificationCompat.Builder)

Posts a notification.

Unit
notify(tag: String?, id: Int, notification: NotificationCompat.Builder)

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

Public functions

areNotificationsEnabled

Added in 1.1.0
fun areNotificationsEnabled(): Boolean

Returns whether notifications from the calling package are not blocked.

cancel

Added in 1.1.0
fun cancel(id: Int): Unit

Cancels a previously shown notification.

See also
cancel

cancel

Added in 1.1.0
fun cancel(tag: String?, id: Int): Unit

Cancels a previously shown notification.

See also
cancel

cancelAll

Added in 1.1.0
fun cancelAll(): Unit

Cancels all previously shown notifications.

See also
cancelAll

createNotificationChannel

Added in 1.1.0
fun createNotificationChannel(channel: NotificationChannelCompat): Unit

Creates a notification channel that notifications can be posted to.

Throws
java.lang.NullPointerException

if channel is null

createNotificationChannelGroup

Added in 1.1.0
fun createNotificationChannelGroup(group: NotificationChannelGroupCompat): Unit

Creates a group container for NotificationChannel objects.

Throws
java.lang.NullPointerException

if group is null

createNotificationChannelGroups

Added in 1.1.0
fun createNotificationChannelGroups(
    groups: (Mutable)List<NotificationChannelGroupCompat!>
): Unit

Creates multiple notification channel groups. See createNotificationChannelGroup.

Throws
java.lang.NullPointerException

if groups is null

createNotificationChannels

Added in 1.1.0
fun createNotificationChannels(
    channels: (Mutable)List<NotificationChannelCompat!>
): Unit

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
fun deleteNotificationChannel(channelId: String): Unit

Deletes the given notification channel.

Throws
java.lang.NullPointerException

if channelId is null

deleteNotificationChannelGroup

Added in 1.1.0
fun deleteNotificationChannelGroup(groupId: String): Unit

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
fun deleteUnlistedNotificationChannels(
    channelIds: (Mutable)Collection<String!>
): Unit

Deletes notification channels for which ids are NOT given.

Throws
java.lang.NullPointerException

if channelIds is null

from

Added in 1.1.0
java-static fun from(context: Context): CarNotificationManager

Returns a CarNotificationManager instance for a provided context.

Throws
java.lang.NullPointerException

if context is null

getEnabledListenerPackages

Added in 1.1.0
java-static fun getEnabledListenerPackages(context: Context): (Mutable)Set<String!>

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
fun getImportance(): Int

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

See also
getImportance

getNotificationChannel

Added in 1.1.0
fun getNotificationChannel(channelId: String): NotificationChannelCompat?

Returns the notification channel settings for a given channel id.

Throws
java.lang.NullPointerException

if channelId is null

getNotificationChannel

Added in 1.1.0
fun getNotificationChannel(channelId: String, conversationId: String): NotificationChannelCompat?

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
fun getNotificationChannelGroup(channelGroupId: String): NotificationChannelGroupCompat?

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
fun getNotificationChannelGroups(): (Mutable)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.

getNotificationChannels

Added in 1.1.0
fun getNotificationChannels(): (Mutable)List<NotificationChannelCompat!>

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
fun notify(id: Int, notification: NotificationCompat.Builder): Unit

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
fun notify(tag: String?, id: Int, notification: NotificationCompat.Builder): Unit

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
tag: String?

the string identifier for a notification. Can be null.

id: Int

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

notification: NotificationCompat.Builder

the notification to post to the system

Throws
java.lang.NullPointerException

if notification is null