當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。