当前位置: 首页>>代码示例>>Java>>正文


Java NotificationManager.getActiveNotifications方法代码示例

本文整理汇总了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();
    }
  }
}
 
开发者ID:XecureIT,项目名称:PeSanKita-android,代码行数:21,代码来源:MessageNotifier.java

示例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();
    }
 
开发者ID:ayc3ue,项目名称:NotificationsApp,代码行数:20,代码来源:MyNLS.java

示例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
                );
            }
        }
    }
}
 
开发者ID:SebastianRask,项目名称:Pocket-Plays-for-Twitch,代码行数:37,代码来源:NotificationReceiver.java

示例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);
    }
  }
}
 
开发者ID:XecureIT,项目名称:PeSanKita-android,代码行数:33,代码来源:MessageNotifier.java

示例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);
    }
  }
}
 
开发者ID:CableIM,项目名称:Cable-Android,代码行数:34,代码来源:MessageNotifier.java


注:本文中的android.app.NotificationManager.getActiveNotifications方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。