android.support.annotation.RestrictTo#android.service.notification.StatusBarNotification源码实例Demo

下面列出了android.support.annotation.RestrictTo#android.service.notification.StatusBarNotification 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: Pi-Locker   文件: Notification.java
@Override
public void onNotificationPosted(StatusBarNotification sbn) {

	Bundle extras = sbn.getNotification().extras;

	String title = extras.getString("android.title");
	String text = extras.getCharSequence("android.text").toString();

	String pack = sbn.getPackageName();
	CharSequence ticker = sbn.getNotification().tickerText;
	boolean ongoing = sbn.isOngoing();
	boolean clearable = sbn.isClearable();

	
	Intent msgrcv = new Intent("Msg");
	msgrcv.putExtra("title", title);
	msgrcv.putExtra("text", text);
	msgrcv.putExtra("p", pack);
	msgrcv.putExtra("c", clearable);
	msgrcv.putExtra("o", ongoing);
	msgrcv.putExtra("t", String.valueOf(ticker));

	
	LocalBroadcastManager.getInstance(context).sendBroadcast(msgrcv);

}
 
源代码2 项目: android_9.0.0_r45   文件: SnoozeHelper.java
protected boolean cancel(int userId, String pkg, String tag, int id) {
    if (mSnoozedNotifications.containsKey(userId)) {
        ArrayMap<String, NotificationRecord> recordsForPkg =
                mSnoozedNotifications.get(userId).get(pkg);
        if (recordsForPkg != null) {
            final Set<Map.Entry<String, NotificationRecord>> records = recordsForPkg.entrySet();
            String key = null;
            for (Map.Entry<String, NotificationRecord> record : records) {
                final StatusBarNotification sbn = record.getValue().sbn;
                if (Objects.equals(sbn.getTag(), tag) && sbn.getId() == id) {
                    record.getValue().isCanceled = true;
                    return true;
                }
            }
        }
    }
    return false;
}
 
源代码3 项目: HeadsUp   文件: NotificationUtils.java
/**
 * Dismisses given notification from system and app.
 */
@SuppressWarnings("deprecation")
@SuppressLint("NewApi")
public static void dismissNotification(@NonNull OpenNotification n) {
    NotificationPresenter.getInstance().removeNotification(n);
    StatusBarNotification sbn = n.getStatusBarNotification();
    if (sbn != null && Device.hasJellyBeanMR2Api()) {
        MediaService service = MediaService.sService;
        if (service != null) {
            if (Device.hasLollipopApi()) {
                service.cancelNotification(sbn.getKey());
            } else {
                service.cancelNotification(
                        sbn.getPackageName(),
                        sbn.getTag(),
                        sbn.getId());
            }
        } else {
            Log.e(TAG, "Failed to dismiss notification because notification service is offline.");
        }
    }
}
 
源代码4 项目: Taskbar   文件: NotificationCountService.java
private void broadcastNotificationCount() {
    int count = 0;

    StatusBarNotification[] notifications;
    try {
        notifications = getActiveNotifications();
    } catch (SecurityException e) {
        notifications = new StatusBarNotification[0];
    }

    for(StatusBarNotification notification : notifications) {
        if((notification.getNotification().flags & NotificationCompat.FLAG_GROUP_SUMMARY) == 0
            && notification.isClearable()) count++;
    }

    broadcastNotificationCount(count);
}
 
源代码5 项目: BaldPhone   文件: NotificationListenerService.java
private void sendBroadcastToHomeScreenActivity() {
    try {
        final StatusBarNotification[] statusBarNotifications = getActiveNotifications();
        final ArrayList<String> packages = new ArrayList<>(statusBarNotifications.length);
        for (final StatusBarNotification statusBarNotification : statusBarNotifications) {
            packages.add(statusBarNotification.getPackageName());

        }
        final Intent intent = new Intent(HOME_SCREEN_ACTIVITY_BROADCAST)
                .putExtra("amount", statusBarNotifications.length)
                .putStringArrayListExtra("packages", packages);

        LocalBroadcastManager.getInstance(this)
                .sendBroadcast(intent);
    } catch (SecurityException e) {
        Log.e(TAG, e.getMessage());
        e.printStackTrace();
    }
}
 
源代码6 项目: MiPushFramework   文件: NotificationListener.java
private boolean checkAppSwitch(OnlineConfig onlineConfig, StatusBarNotification statusBarNotification) {
    boolean z = true;
    String stringValue = onlineConfig.getStringValue(ConfigKey.CollectionNotificationInfoAppSwitch.getValue(), "b");
    if (TextUtils.isEmpty(stringValue)) {
        return false;
    }
    List emptyList = Collections.emptyList();
    if (stringValue.length() > 1) {
        emptyList = Arrays.asList(stringValue.substring(1).split(";"));
    }
    String packageName = statusBarNotification.getPackageName();
    char charAt = stringValue.charAt(0);
    if (charAt != 'b') {
        return charAt == 'w' ? emptyList.contains(packageName) : false;
    } else {
        if (emptyList.contains(packageName)) {
            z = false;
        }
        return z;
    }
}
 
源代码7 项目: GravityBox   文件: ProgressBarController.java
private ProgressInfo verifyNotification(StatusBarNotification statusBarNotif) {
    if (statusBarNotif == null)
        return null;

    String id = getIdentifier(statusBarNotif);
    if (id == null)
        return null;

    Notification n = statusBarNotif.getNotification();
    if (n != null && 
           (SUPPORTED_PACKAGES.contains(statusBarNotif.getPackageName()) ||
            n.extras.getBoolean(ModLedControl.NOTIF_EXTRA_PROGRESS_TRACKING))) {
        ProgressInfo pi = getProgressInfo(id, n);
        if (pi != null && pi.hasProgressBar)
            return pi;
    }
    return null;
}
 
源代码8 项目: NotificationPeekPort   文件: NotificationHelper.java
public static boolean shouldDisplayNotification(StatusBarNotification oldNotif,
                                                StatusBarNotification newNotif) {
    // First check for ticker text, if they are different, some other parameters will be
    // checked to determine if we should show the notification.
    CharSequence oldTickerText = oldNotif.getNotification().tickerText;
    CharSequence newTickerText = newNotif.getNotification().tickerText;
    if (newTickerText == null ? oldTickerText == null : newTickerText.equals(oldTickerText)) {
        // If old notification title isn't null, show notification if
        // new notification title is different. If it is null, show notification
        // if the new one isn't.
        String oldNotificationText = getNotificationTitle(oldNotif);
        String newNotificationText = getNotificationTitle(newNotif);
        if (newNotificationText == null ? oldNotificationText != null : !newNotificationText
                .equals(oldNotificationText)) {
            return true;
        }

        // Last chance, check when the notifications were posted. If times
        // are equal, we shouldn't display the new notification.
        if (oldNotif.getNotification().when != newNotif.getNotification().when) {
            return true;
        }
        return false;
    }
    return true;
}
 
源代码9 项目: android-common   文件: NotificationService.java
@Override
public void onNotificationPosted(StatusBarNotification sbn) {
    if (Log.isPrint) {
        Log.i(TAG, sbn.toString());
        Notification notification = sbn.getNotification();
        Log.i(TAG, "tickerText : " + notification.tickerText);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            Bundle bundle = notification.extras;
            for (String key : bundle.keySet()) {
                Log.i(TAG, key + ": " + bundle.get(key));
            }
        }
    }
    if (self != null && notificationListener != null) {
        notificationListener.onNotificationPosted(sbn);
    }
}
 
源代码10 项目: retrowatch   文件: NotificationReceiverService.java
@Override
public void onReceive(Context context, Intent intent) {
    if(intent.getStringExtra("command").equals("clearall")){
    	NotificationReceiverService.this.cancelAllNotifications();
    }
    else if(intent.getStringExtra("command").equals("list")){
        for (StatusBarNotification sbn : NotificationReceiverService.this.getActiveNotifications()) {
            Intent i2 = new  Intent(Constants.NOTIFICATION_LISTENER);
            i2.putExtra(NOTIFICATION_KEY_CMD, NOTIFICATION_CMD_LIST);
            i2.putExtra(NOTIFICATION_KEY_ID, sbn.getId());
            i2.putExtra(NOTIFICATION_KEY_PACKAGE, sbn.getPackageName());
            i2.putExtra(NOTIFICATION_KEY_TEXT, sbn.getNotification().tickerText);
            sendBroadcast(i2);
        }
    }

}
 
源代码11 项目: an2linuxclient   文件: Notification.java
@RequiresApi(Build.VERSION_CODES.KITKAT)
private void extractTitle(StatusBarNotification sbn, PackageManager pm) {
    Bundle extras = sbn.getNotification().extras;

    String contentTitle = "";
    CharSequence temp = extras.getCharSequence(android.app.Notification.EXTRA_TITLE);
    if (temp != null){
        contentTitle = temp.toString();
    }

    String appName = getAppName(pm, sbn.getPackageName());

    title = "";

    if (ns.forceTitle()){
        title = appName;
    } else {
        if (!contentTitle.equals("")){
            title = contentTitle;
        } else {
            title = appName;
        }
    }

    title = title.trim();
}
 
源代码12 项目: LaunchEnr   文件: NotificationListener.java
@Override
public boolean handleMessage(Message message) {
    switch (message.what) {
        case MSG_NOTIFICATION_POSTED:
            if (sNotificationsChangedListener != null) {
                NotificationPostedMsg msg = (NotificationPostedMsg) message.obj;
                sNotificationsChangedListener.onNotificationPosted(msg.packageUserKey,
                        msg.notificationKey, msg.shouldBeFilteredOut);
            }
            break;
        case MSG_NOTIFICATION_REMOVED:
            if (sNotificationsChangedListener != null) {
                Pair<PackageUserKey, NotificationKeyData> pair
                        = (Pair<PackageUserKey, NotificationKeyData>) message.obj;
                sNotificationsChangedListener.onNotificationRemoved(pair.first, pair.second);
            }
            break;
        case MSG_NOTIFICATION_FULL_REFRESH:
            if (sNotificationsChangedListener != null) {
                sNotificationsChangedListener.onNotificationFullRefresh(
                        (List<StatusBarNotification>) message.obj);
            }
            break;
    }
    return true;
}
 
源代码13 项目: AcDisplay   文件: NotificationPresenter.java
void init(final @NonNull Context context,
          final @NonNull StatusBarNotification[] activeNotifications) {
    mHandler.post(new Runnable() {
        @SuppressLint("NewApi")
        @Override
        public void run() {
            clear(false);

            if (DEBUG) Log.d(TAG, "Initializing the notifications list...");
            // Initialize the notifications list through the proxy to
            // optimize the process. This is completely not useful on
            // pre-Lollipop devices due to lack of children notifications.
            List<NotificationPrTask> list = new ArrayList<>(activeNotifications.length);
            for (StatusBarNotification sbn : activeNotifications) {
                OpenNotification n = OpenNotification.newInstance(sbn);
                list.add(new NotificationPrTask(context, n, true /* post */, 0));
            }
            if (Device.hasLollipopApi()) mProxy.optimizePrTasks(list);
            mProxy.sendPrTasks(list);
            list.clear(); // This is probably not needed.
        }
    });
}
 
源代码14 项目: 365browser   文件: DownloadNotificationService.java
/**
 * Returns whether or not there are any download notifications showing that aren't the summary
 * notification.
 * @param notificationIdToIgnore If not -1, the id of a notification to ignore and
 *                               assume is closing or about to be closed.
 * @return Whether or not there are valid download notifications currently visible.
 */
@TargetApi(Build.VERSION_CODES.M)
private static boolean hasDownloadNotifications(
        NotificationManager manager, int notificationIdToIgnore) {
    if (!useForegroundService()) return false;

    StatusBarNotification[] notifications = manager.getActiveNotifications();
    for (StatusBarNotification notification : notifications) {
        boolean isDownloadsGroup = TextUtils.equals(notification.getNotification().getGroup(),
                NotificationConstants.GROUP_DOWNLOADS);
        boolean isSummaryNotification =
                notification.getId() == NotificationConstants.NOTIFICATION_ID_DOWNLOAD_SUMMARY;
        boolean isIgnoredNotification =
                notificationIdToIgnore != -1 && notificationIdToIgnore == notification.getId();
        if (isDownloadsGroup && !isSummaryNotification && !isIgnoredNotification) return true;
    }

    return false;
}
 
源代码15 项目: things-notification   文件: NotificationListener.java
@Override
public void onNotificationPosted(StatusBarNotification sbn) {
    Log.d(TAG, "Notification received: "+sbn.getPackageName()+":"+sbn.getNotification().tickerText);

    if (sbn.getNotification().tickerText == null) {
        return;
    }

    WritableNativeMap params = new WritableNativeMap();
    params.putString("text", sbn.getNotification().tickerText.toString());

    String app = sbn.getPackageName();
    if (app.equals(NotificationModule.smsApp)) {
        params.putString("app", "sms");
    } else {
        params.putString("app", app);
    }

    NotificationModule.sendEvent("notificationReceived", params);
}
 
源代码16 项目: meter   文件: NotificationService.java
/**
 * Called when notifications are removed
 */
@Override
public void onNotificationRemoved(StatusBarNotification sbn) {
    Intent intent = new  Intent(NOTIFICATION_UPDATE);
    intent.putExtra(NotificationKey.ACTION, NotificationAction.NOTIFICATION_REMOVED);
    intent.putExtra(NotificationKey.APPLICATION_PACKAGE_NAME,sbn.getPackageName());

    // List the notifications in a string array
    StatusBarNotification[] activeNotifications = NotificationService.this.getActiveNotifications();
    String packages[] = new String[activeNotifications.length];
    int i = 0;
    for (StatusBarNotification nf : activeNotifications) {
        packages[i++] = nf.getPackageName();
    }
    intent.putExtra(NotificationKey.APPLICATION_PACKAGES, packages);

    // Broadcast the intent
    sendBroadcast(intent);

    numNotifications = packages.length;
}
 
源代码17 项目: zephyr   文件: NotificationService.java
@Override
public void onNotificationRemoved(@Nullable StatusBarNotification sbn) {
    if (sbn == null) {
        logger.log(LogLevel.WARNING, LOG_TAG, "onNotificationRemoved: StatusBarNotification is null");
        return;
    }

    logger.log(LogLevel.VERBOSE, LOG_TAG, "onNotificationRemoved: [%s]\t%s", sbn.getId(), sbn.getPackageName());
    ZephyrExecutors.getDiskExecutor().execute(() -> {
        if (isValidNotification(sbn)) {
            DismissNotificationPayload dismissNotificationPayload = new DismissNotificationPayload();
            dismissNotificationPayload.packageName = sbn.getPackageName();
            dismissNotificationPayload.id = sbn.getId();

            logger.log(LogLevel.VERBOSE, LOG_TAG, "Dismissing notification: %s", sbn.getId());
            EventBus.getDefault().post(dismissNotificationPayload);
        }
    });
}
 
源代码18 项目: android_9.0.0_r45   文件: GroupHelper.java
/**
 * Un-autogroups notifications that are now grouped by the app.
 */
private void maybeUngroup(StatusBarNotification sbn, boolean notificationGone, int userId) {
    List<String> notificationsToUnAutogroup = new ArrayList<>();
    boolean removeSummary = false;
    synchronized (mUngroupedNotifications) {
        Map<String, LinkedHashSet<String>> ungroupedNotificationsByUser
                = mUngroupedNotifications.get(sbn.getUserId());
        if (ungroupedNotificationsByUser == null || ungroupedNotificationsByUser.size() == 0) {
            return;
        }
        LinkedHashSet<String> notificationsForPackage
                = ungroupedNotificationsByUser.get(sbn.getPackageName());
        if (notificationsForPackage == null || notificationsForPackage.size() == 0) {
            return;
        }
        if (notificationsForPackage.remove(sbn.getKey())) {
            if (!notificationGone) {
                // Add the current notification to the ungrouping list if it still exists.
                notificationsToUnAutogroup.add(sbn.getKey());
            }
        }
        // If the status change of this notification has brought the number of loose
        // notifications to zero, remove the summary and un-autogroup.
        if (notificationsForPackage.size() == 0) {
            ungroupedNotificationsByUser.remove(sbn.getPackageName());
            removeSummary = true;
        }
    }
    if (removeSummary) {
        adjustAutogroupingSummary(userId, sbn.getPackageName(), null, false);
    }
    if (notificationsToUnAutogroup.size() > 0) {
        adjustNotificationBundling(notificationsToUnAutogroup, false);
    }
}
 
源代码19 项目: linphone-android   文件: Compatibility.java
public static StatusBarNotification[] getActiveNotifications(NotificationManager manager) {
    if (Version.sdkAboveOrEqual(Version.API23_MARSHMALLOW_60)) {
        return ApiTwentyThreePlus.getActiveNotifications(manager);
    }

    return new StatusBarNotification[0];
}
 
源代码20 项目: zephyr   文件: NotificationService.java
private boolean isValidNotification(@NonNull StatusBarNotification sbn) {
    if (sbn.getPackageName().equals(BuildConfig.APPLICATION_ID)) {
        logger.log(LogLevel.DEBUG, LOG_TAG, "Invalid notification: Zephyr");
        return false;
    }

    if (!sbn.isClearable()) {
        logger.log(LogLevel.DEBUG, LOG_TAG, "Invalid notification: Not clearable");
        return false;
    }

    if (getPackageManager().getLaunchIntentForPackage(sbn.getPackageName()) == null) {
        logger.log(LogLevel.DEBUG, LOG_TAG, "Invalid notification: No launch intent");
        return false;
    }

    INotificationPreference notificationPreference = notificationPreferenceRepository.getNotificationPreferenceSync(sbn.getPackageName());
    if (notificationPreference == null) {
        logger.log(LogLevel.DEBUG, LOG_TAG, "Invalid notification: null preference");
        return false;
    }

    if (!notificationPreference.isEnabled()) {
        logger.log(LogLevel.DEBUG, LOG_TAG, "Invalid notification: Disabled");
        return false;
    }

    logger.log(LogLevel.DEBUG, LOG_TAG, "Valid notification.");
    return true;
}
 
@Override
public void onNotificationPosted(StatusBarNotification sbn) {
    super.onNotificationPosted(sbn);
    Log.d(TAG, "onNotificationPosted");

    Notification notification = sbn.getNotification();

    String packageName = sbn.getPackageName();
    long time = sbn.getPostTime();
    String title = notification.extras.getString(Notification.EXTRA_TITLE);
    String text = notification.extras.getString(Notification.EXTRA_TEXT);

    DbUtils.saveNotification(new NotificationInfo(packageName, title, text, time));
    List<AppInfo> blackList = DbUtils.getApp();

    for (AppInfo app : blackList) {
        if (packageName.equals(app.getPackageName())) {
            Log.d(TAG, packageName + " 拦截:" + title + ": " + text);

            if (android.os.Build.VERSION.SDK_INT > Build.VERSION_CODES.KITKAT_WATCH) {
                cancelNotification(sbn.getKey());
            } else {
                cancelNotification(sbn.getPackageName(), sbn.getTag(), sbn.getId());
            }

            if (SettingUtils.getInstance().isNotify()) {
                createNotification(app.getAppName(), packageName, title, text);
            }
        }
    }
}
 
源代码22 项目: NotificationPeekPort   文件: NotificationPeek.java
public void removeNotification(StatusBarNotification n) {
    for (int i = 0; i < mShownNotifications.size(); i++) {
        if (NotificationHelper.getContentDescription(n)
                .equals(NotificationHelper.getContentDescription(mShownNotifications.get(i)))) {
            mShownNotifications.remove(i);
            i--;
        }
    }
    updateNotificationIcons();
}
 
public void removeIncomingCallNotification(ReactApplicationContext context,
                                           CallInvite callInvite,
                                           int notificationId) {
    Log.d(TAG, "removeIncomingCallNotification");
    NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
    if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M) {
        if (callInvite != null && callInvite.getState() == CallInvite.State.PENDING) {
            /*
             * If the incoming call message was cancelled then remove the notification by matching
             * it with the call sid from the list of notifications in the notification drawer.
             */
            StatusBarNotification[] activeNotifications = notificationManager.getActiveNotifications();
            for (StatusBarNotification statusBarNotification : activeNotifications) {
                Notification notification = statusBarNotification.getNotification();
                String notificationType = notification.extras.getString(NOTIFICATION_TYPE);
                if (callInvite.getCallSid().equals(notification.extras.getString(CALL_SID_KEY)) &&
                        notificationType != null && notificationType.equals(ACTION_INCOMING_CALL)) {
                    notificationManager.cancel(notification.extras.getInt(INCOMING_CALL_NOTIFICATION_ID));
                }
            }
        } else if (notificationId != 0) {
            notificationManager.cancel(notificationId);
        }
    } else {
        if (notificationId != 0) {
            notificationManager.cancel(notificationId);
        } else if (callInvite != null) {
            String notificationKey = INCOMING_NOTIFICATION_PREFIX+callInvite.getCallSid();
            if (TwilioVoiceModule.callNotificationMap.containsKey(notificationKey)) {
                notificationId = TwilioVoiceModule.callNotificationMap.get(notificationKey);
                notificationManager.cancel(notificationId);
                TwilioVoiceModule.callNotificationMap.remove(notificationKey);
            }
        }
    }
}
 
源代码24 项目: HeadsUp   文件: NotificationListenerLollipop.java
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2)
@Override
public void onListenerConnected(@NonNull NotificationListenerService service) {
    StatusBarNotification[] an = service.getActiveNotifications();
    if (an == null) return;
    NotificationPresenter np = NotificationPresenter.getInstance();
    np.init(service, an);
}
 
源代码25 项目: sdk   文件: NevoDecoratorService.java
/**
 * Retrieve historic notifications posted with the given key (including the incoming one without decoration at the last).
 * The number of notifications kept in archive is undefined.
 *
 * Decorator permission restriction applies.
 */
protected final List<StatusBarNotification> getArchivedNotifications(final String key, final int limit) {
	try {
		return mController.getNotifications(mWrapper, TYPE_ARCHIVED, singletonList(key), limit, null);
	} catch (final RemoteException e) {
		Log.w(TAG, "Error retrieving archived notifications: " + key, e);
		return Collections.emptyList();
	}
}
 
public static StatusBarNotification[] getAllActiveNotifications() {
	if(instance != null) {
		try {
			return instance.getActiveNotifications();
		} catch (Exception e) {
			if(Const.DEBUG) e.printStackTrace();
		}
	}
	return null;
}
 
源代码27 项目: AcDisplay   文件: OpenNotification.java
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2)
@NonNull
static OpenNotification newInstance(@NonNull StatusBarNotification sbn) {
    Notification n = sbn.getNotification();
    if (Device.hasLollipopApi()) {
        return new OpenNotificationLollipop(sbn, n);
    } else if (Device.hasKitKatWatchApi()) {
        return new OpenNotificationKitKatWatch(sbn, n);
    }

    return new OpenNotificationJellyBeanMR2(sbn, n);
}
 
@SuppressWarnings("BooleanMethodIsAlwaysInverted")
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2)
private boolean postActiveNotifications(@NonNull NotificationListenerService service) {
    StatusBarNotification[] an = service.getActiveNotifications();
    if (an == null) return false;
    NotificationPresenter np = NotificationPresenter.getInstance();
    np.init(service, an);
    return mInitialized = true;
}
 
源代码29 项目: GravityBox   文件: LockscreenAppBar.java
@Override
public void onNotificationDataChanged(final StatusBarNotification sbn) {
    for (AppInfo ai : mAppSlots) {
        if (ai.getPackageName() == null)
            continue;

        if (sbn == null || sbn.getPackageName() == null ||
                sbn.getPackageName().equals(ai.getPackageName())) {
            ai.updateIcon();
        }
    }
}
 
源代码30 项目: Botifier   文件: BotifierNotificationService.java
@Override
public void onNotificationRemoved(StatusBarNotification statusnotification) {
	Log.d(TAG, "Cleaning up notifications");
	Message msg = new Message();
	msg.obj = statusnotification;
	msg.arg1 = 1;
	mHandler.sendMessage(msg);
}