本文整理汇总了Java中android.app.NotificationManager.getActiveNotifications方法的典型用法代码示例。如果您正苦于以下问题:Java NotificationManager.getActiveNotifications方法的具体用法?Java NotificationManager.getActiveNotifications怎么用?Java NotificationManager.getActiveNotifications使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.app.NotificationManager
的用法示例。
在下文中一共展示了NotificationManager.getActiveNotifications方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: cancelActiveNotifications
import android.app.NotificationManager; //导入方法依赖的package包/类
private static void cancelActiveNotifications(@NonNull Context context) {
NotificationManager notifications = ServiceUtil.getNotificationManager(context);
notifications.cancel(SUMMARY_NOTIFICATION_ID);
if (Build.VERSION.SDK_INT >= 23) {
try {
StatusBarNotification[] activeNotifications = notifications.getActiveNotifications();
for (StatusBarNotification activeNotification : activeNotifications) {
if (activeNotification.getId() != CallNotificationBuilder.WEBRTC_NOTIFICATION) {
notifications.cancel(activeNotification.getId());
}
}
} catch (Throwable e) {
// XXX Appears to be a ROM bug, see #6043
Log.w(TAG, e);
notifications.cancelAll();
}
}
}
示例2: onListenerConnected
import android.app.NotificationManager; //导入方法依赖的package包/类
@Override
public void onListenerConnected() {
super.onListenerConnected();
//here is where we disable the notifications
NotificationManager notification = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
StatusBarNotification[] n = notification.getActiveNotifications();
Log.d("MainActivity.java", Integer.toString(n.length));
// TextView check2 = (TextView) findViewById(R.id.didPackagework);
// check2.setText(n.toString());
for(int i = 0; i < n.length; i++) {
Log.d("MainActivity.java", n[i].toString() );
// TextView mylist = (TextView) findViewById(R.id.didPackagework);
// mylist.setText(n[i].toString());
}
Log.d("MyNLS.java", "in here");
StatusBarNotification[] notifications = getActiveNotifications();
// notifications.getPackageName();
}
示例3: updateCurrentNotifications
import android.app.NotificationManager; //导入方法依赖的package包/类
private void updateCurrentNotifications(NotificationFetchData notificationFetchData, NotificationManager notificationManager, Context context) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
return;
}
// This try-catch is needed because of an Android 6.0 issue where calling getActiveNotifications may throw a nullpointerexception
// https://github.com/googlesamples/android-ActiveNotifications/issues/1
try {
if (notificationManager == null || notificationManager.getActiveNotifications() == null) {
return;
}
} catch (NullPointerException e) {
return;
}
// Nested for loops :/
for (StatusBarNotification statusBarNotification : notificationManager.getActiveNotifications()) {
for (StreamInfo stream : notificationFetchData.getCurrentlyOnlineStreams()) {
if (stream.getChannelInfo().getNotificationTag().equals(statusBarNotification.getTag())) {
Notification notification = createStreamNotification(
stream,
getLargeIconFromNotification(statusBarNotification.getNotification(), context),
true,
context
);
notificationManager.notify(
stream.getChannelInfo().getNotificationTag(),
NOTIFICATION_ID,
notification
);
}
}
}
}
示例4: cancelOrphanedNotifications
import android.app.NotificationManager; //导入方法依赖的package包/类
private static void cancelOrphanedNotifications(@NonNull Context context, NotificationState notificationState) {
if (Build.VERSION.SDK_INT >= 23) {
try {
NotificationManager notifications = ServiceUtil.getNotificationManager(context);
StatusBarNotification[] activeNotifications = notifications.getActiveNotifications();
for (StatusBarNotification notification : activeNotifications) {
boolean validNotification = false;
if (notification.getId() != SUMMARY_NOTIFICATION_ID &&
notification.getId() != CallNotificationBuilder.WEBRTC_NOTIFICATION &&
notification.getId() != KeyCachingService.SERVICE_RUNNING_ID &&
notification.getId() != MessageRetrievalService.FOREGROUND_ID)
{
for (NotificationItem item : notificationState.getNotifications()) {
if (notification.getId() == (SUMMARY_NOTIFICATION_ID + item.getThreadId())) {
validNotification = true;
break;
}
}
if (!validNotification) {
notifications.cancel(notification.getId());
}
}
}
} catch (Throwable e) {
// XXX Android ROM Bug, see #6043
Log.w(TAG, e);
}
}
}
示例5: cancelOrphanedNotifications
import android.app.NotificationManager; //导入方法依赖的package包/类
private static void cancelOrphanedNotifications(@NonNull Context context, NotificationState notificationState) {
if (Build.VERSION.SDK_INT >= 23) {
try {
NotificationManager notifications = ServiceUtil.getNotificationManager(context);
StatusBarNotification[] activeNotifications = notifications.getActiveNotifications();
for (StatusBarNotification notification : activeNotifications) {
boolean validNotification = false;
if (notification.getId() != SUMMARY_NOTIFICATION_ID &&
notification.getId() != CallNotificationBuilder.WEBRTC_NOTIFICATION &&
notification.getId() != KeyCachingService.SERVICE_RUNNING_ID &&
notification.getId() != MessageRetrievalService.FOREGROUND_ID &&
notification.getId() != PENDING_MESSAGES_ID)
{
for (NotificationItem item : notificationState.getNotifications()) {
if (notification.getId() == (SUMMARY_NOTIFICATION_ID + item.getThreadId())) {
validNotification = true;
break;
}
}
if (!validNotification) {
notifications.cancel(notification.getId());
}
}
}
} catch (Throwable e) {
// XXX Android ROM Bug, see #6043
Log.w(TAG, e);
}
}
}