Java Code Examples for android.service.notification.NotificationListenerService#RankingMap

The following examples show how to use android.service.notification.NotificationListenerService#RankingMap . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: NLService.java    From fitnotifications with Apache License 2.0 6 votes vote down vote up
@Override
public void onNotificationPosted(StatusBarNotification sbn,
                                 NotificationListenerService.RankingMap rankingMap) {

    if (mForwardOnlyPriorityNotifs) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP &&
                mInterruptionFilter == INTERRUPTION_FILTER_PRIORITY) {
            String packageName = sbn.getPackageName();
            String rankingKey = null;
            for (String s : rankingMap.getOrderedKeys()) {
                if (s.contains(packageName)) {
                    rankingKey = s;
                    break;
                }
            }

            Ranking ranking = new Ranking();
            if (rankingKey != null && rankingMap.getRanking(rankingKey, ranking)) {
                if (!ranking.matchesInterruptionFilter()) {
                    return;
                }
            }
        }
    }
    onNotificationPosted(sbn);
}
 
Example 2
Source File: NotificationListener.java    From android-notification-log with MIT License 5 votes vote down vote up
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public static NotificationListenerService.RankingMap getRanking() {
	if(instance != null) {
		try {
			return instance.getCurrentRanking();
		} catch (Exception e) {
			if(Const.DEBUG) e.printStackTrace();
		}
	}
	return null;
}
 
Example 3
Source File: GetAwayNotificationListenerService.java    From timecat with Apache License 2.0 4 votes vote down vote up
@TargetApi(21)
public void onNotificationPosted(StatusBarNotification paramStatusBarNotification, NotificationListenerService.RankingMap paramRankingMap) {
    super.onNotificationPosted(paramStatusBarNotification, paramRankingMap);
}
 
Example 4
Source File: GetAwayNotificationListenerService.java    From timecat with Apache License 2.0 4 votes vote down vote up
@TargetApi(21)
public void onNotificationRankingUpdate(NotificationListenerService.RankingMap paramRankingMap) {
    super.onNotificationRankingUpdate(paramRankingMap);
}
 
Example 5
Source File: GetAwayNotificationListenerService.java    From timecat with Apache License 2.0 4 votes vote down vote up
@TargetApi(21)
public void onNotificationRemoved(StatusBarNotification paramStatusBarNotification, NotificationListenerService.RankingMap paramRankingMap) {
    super.onNotificationRemoved(paramStatusBarNotification, paramRankingMap);
}
 
Example 6
Source File: NotificationObject.java    From android-notification-log with MIT License 4 votes vote down vote up
private void extract()  {
	// General
	when           = n.when;
	flags          = n.flags;
	defaults       = n.defaults;
	ledARGB        = n.ledARGB;
	ledOff         = n.ledOffMS;
	ledOn          = n.ledOnMS;

	if(Build.VERSION.SDK_INT < 24) { // as of 24, this number is not shown anymore
		number = n.number;
	} else {
		number = -1;
	}

	// Device
	ringerMode     = Util.getRingerMode(context);
	isScreenOn     = Util.isScreenOn(context);
	batteryLevel   = Util.getBatteryLevel(context);
	batteryStatus  = Util.getBatteryStatus(context);
	isConnected    = Util.isNetworkAvailable(context);
	connectionType = Util.getConnectivityType(context);

	// 16
	priority = n.priority;

	// 21
	if(Build.VERSION.SDK_INT >= 21) {
		visibility = n.visibility;
		color      = n.color;

		listenerHints = NotificationListener.getListenerHints();
		interruptionFilter = NotificationListener.getInterruptionFilter();
		NotificationListenerService.Ranking ranking = new NotificationListenerService.Ranking();
		NotificationListenerService.RankingMap rankingMap = NotificationListener.getRanking();
		if(rankingMap != null && rankingMap.getRanking(key, ranking)) {
			matchesInterruptionFilter = ranking.matchesInterruptionFilter();
		}
	}

	// Compat
	group          = NotificationCompat.getGroup(n);
	isGroupSummary = NotificationCompat.isGroupSummary(n);
	category       = NotificationCompat.getCategory(n);
	actionCount    = NotificationCompat.getActionCount(n);
	isLocalOnly    = NotificationCompat.getLocalOnly(n);

	Bundle extras = NotificationCompat.getExtras(n);
	if(extras != null) {
		String[] tmp = extras.getStringArray(NotificationCompat.EXTRA_PEOPLE);
		people = tmp != null ? Arrays.asList(tmp) : null;
		style  = extras.getString(NotificationCompat.EXTRA_TEMPLATE);
	}

	// Text
	if(LOG_TEXT) {
		appName    = Util.getAppNameFromPackage(context, packageName, false);
		tickerText = Util.nullToEmptyString(n.tickerText);

		if(extras != null) {
			title       = Util.nullToEmptyString(extras.getCharSequence(NotificationCompat.EXTRA_TITLE));
			titleBig    = Util.nullToEmptyString(extras.getCharSequence(NotificationCompat.EXTRA_TITLE_BIG));
			text        = Util.nullToEmptyString(extras.getCharSequence(NotificationCompat.EXTRA_TEXT));
			textBig     = Util.nullToEmptyString(extras.getCharSequence(NotificationCompat.EXTRA_BIG_TEXT));
			textInfo    = Util.nullToEmptyString(extras.getCharSequence(NotificationCompat.EXTRA_INFO_TEXT));
			textSub     = Util.nullToEmptyString(extras.getCharSequence(NotificationCompat.EXTRA_SUB_TEXT));
			textSummary = Util.nullToEmptyString(extras.getCharSequence(NotificationCompat.EXTRA_SUMMARY_TEXT));

			CharSequence[] lines = extras.getCharSequenceArray(NotificationCompat.EXTRA_TEXT_LINES);
			if(lines != null) {
				textLines = "";
				for(CharSequence line : lines) {
					textLines += line + "\n";
				}
				textLines = textLines.trim();
			}
		}
	}
}