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 |
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 |
void |
Creates multiple notification channel groups. |
void |
createNotificationChannels(Creates multiple notification channels that different notifications can be posted to. |
void |
deleteNotificationChannel(@NonNull String channelId)Deletes the given notification channel. |
void |
deleteNotificationChannelGroup(@NonNull String groupId)Deletes the given notification channel group, and all notification channels that belong to it. |
void |
deleteUnlistedNotificationChannels(Deletes notification channels for which ids are NOT given. |
static @NonNull CarNotificationManager |
Returns a |
static @NonNull Set<String> |
getEnabledListenerPackages(@NonNull Context context)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 |
getNotificationChannel(@NonNull String channelId)Returns the notification channel settings for a given channel id. |
@Nullable NotificationChannelCompat |
getNotificationChannel(Returns the notification channel settings for a given channel and |
@Nullable NotificationChannelGroupCompat |
getNotificationChannelGroup(@NonNull String channelGroupId)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(Post a notification to be shown in the status bar, stream, etc. |
Public methods
areNotificationsEnabled
public boolean areNotificationsEnabled()
Returns whether notifications from the calling package are not blocked.
| See also | |
|---|---|
areNotificationsEnabled |
cancel
public void cancel(int id)
Cancels a previously shown notification.
| See also | |
|---|---|
cancel |
cancel
public void cancel(@Nullable String tag, int id)
Cancels a previously shown notification.
| See also | |
|---|---|
cancel |
cancelAll
public void cancelAll()
Cancels all previously shown notifications.
| See also | |
|---|---|
cancelAll |
createNotificationChannel
public void createNotificationChannel(@NonNull NotificationChannelCompat channel)
Creates a notification channel that notifications can be posted to.
| Throws | |
|---|---|
java.lang.NullPointerException |
if |
| See also | |
|---|---|
createNotificationChannel |
createNotificationChannelGroup
public void createNotificationChannelGroup(
@NonNull NotificationChannelGroupCompat group
)
Creates a group container for NotificationChannel objects.
| Throws | |
|---|---|
java.lang.NullPointerException |
if |
| See also | |
|---|---|
createNotificationChannelGroup |
createNotificationChannelGroups
public void createNotificationChannelGroups(
@NonNull List<NotificationChannelGroupCompat> groups
)
Creates multiple notification channel groups. See createNotificationChannelGroup.
| Throws | |
|---|---|
java.lang.NullPointerException |
if |
createNotificationChannels
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 |
| See also | |
|---|---|
createNotificationChannelsCompat |
deleteNotificationChannel
public void deleteNotificationChannel(@NonNull String channelId)
Deletes the given notification channel.
| Throws | |
|---|---|
java.lang.NullPointerException |
if |
| See also | |
|---|---|
deleteNotificationChannel |
deleteNotificationChannelGroup
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 |
| See also | |
|---|---|
deleteNotificationChannelGroup |
deleteUnlistedNotificationChannels
public void deleteUnlistedNotificationChannels(
@NonNull Collection<String> channelIds
)
Deletes notification channels for which ids are NOT given.
| Throws | |
|---|---|
java.lang.NullPointerException |
if |
| See also | |
|---|---|
deleteUnlistedNotificationChannels |
from
public static @NonNull CarNotificationManager from(@NonNull Context context)
Returns a CarNotificationManager instance for a provided context.
| Throws | |
|---|---|
java.lang.NullPointerException |
if |
getEnabledListenerPackages
public static @NonNull Set<String> getEnabledListenerPackages(@NonNull Context context)
Get the set of packages that have an enabled notification listener component within them.
| Throws | |
|---|---|
java.lang.NullPointerException |
if |
| See also | |
|---|---|
getEnabledListenerPackages |
getImportance
public int getImportance()
Returns the user specified importance for notifications from the calling package.
| See also | |
|---|---|
getImportance |
getNotificationChannel
public @Nullable NotificationChannelCompat getNotificationChannel(@NonNull String channelId)
Returns the notification channel settings for a given channel id.
| Throws | |
|---|---|
java.lang.NullPointerException |
if |
| See also | |
|---|---|
getNotificationChannelCompat |
getNotificationChannel
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 |
| See also | |
|---|---|
getNotificationChannelCompat |
getNotificationChannelGroup
public @Nullable NotificationChannelGroupCompat getNotificationChannelGroup(@NonNull String channelGroupId)
Returns the notification channel group settings for a given channel group id.
| Throws | |
|---|---|
java.lang.NullPointerException |
if |
| See also | |
|---|---|
getNotificationChannelGroupCompat |
getNotificationChannelGroups
public @NonNull List<NotificationChannelGroupCompat> getNotificationChannelGroups()
Returns all notification channel groups belonging to the calling app or an empty list on older SDKs which don't support Notification Channels.
| See also | |
|---|---|
getNotificationChannelGroupsCompat |
getNotificationChannels
public @NonNull List<NotificationChannelCompat> getNotificationChannels()
Returns all notification channels belonging to the calling app or an empty list on older SDKs which don't support Notification Channels.
| See also | |
|---|---|
getNotificationChannelsCompat |
notify
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 |
| See also | |
|---|---|
notify |
notify
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 |
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 |