Java Code Examples for androidx.core.app.NotificationCompat#getLocalOnly()

The following examples show how to use androidx.core.app.NotificationCompat#getLocalOnly() . 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: 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();
			}
		}
	}
}
 
Example 2
Source File: NLService.java    From AsteroidOSSync with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void onNotificationPosted(StatusBarNotification sbn) {
    Notification notification = sbn.getNotification();
    String packageName = sbn.getPackageName();

    String[] allowedOngoingApps = {"com.google.android.apps.maps"};
    if((notification.priority < Notification.PRIORITY_DEFAULT) ||
       ((notification.flags & Notification.FLAG_ONGOING_EVENT) != 0
        && !Arrays.asList(allowedOngoingApps).contains(packageName)) ||
       (NotificationCompat.getLocalOnly(notification)) ||
       (NotificationCompat.isGroupSummary(notification)))
        return;

    NotificationParser notifParser = new NotificationParser(notification);
    String summary = notifParser.summary;
    String body = notifParser.body;
    int id = sbn.getId();
    String appIcon = iconFromPackage.get(packageName);

    String appName = "";
    try {
        final PackageManager pm = getApplicationContext().getPackageManager();
        ApplicationInfo ai = pm.getApplicationInfo(packageName, 0);
        appName = pm.getApplicationLabel(ai).toString();
    } catch (PackageManager.NameNotFoundException ignored) {}

    if(summary == null) summary = "";
    else                summary = summary.trim();
    if(body == null) body = "";
    else                body = body.trim();
    if(packageName == null) packageName = "";
    if(appIcon == null) appIcon = "";

    Intent i = new  Intent("org.asteroidos.sync.NOTIFICATION_LISTENER");
    i.putExtra("event", "posted");
    i.putExtra("packageName", packageName);
    i.putExtra("id", id);
    i.putExtra("appName", appName);
    i.putExtra("appIcon", appIcon);
    i.putExtra("summary", summary);
    i.putExtra("body", body);

    sendBroadcast(i);
}