Java Code Examples for android.app.Notification#PRIORITY_MIN

The following examples show how to use android.app.Notification#PRIORITY_MIN . 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: ShortcutNotificationManager.java    From HayaiLauncher with Apache License 2.0 5 votes vote down vote up
public static int getPriorityFromString(String priority) {
    int i_priority = 0;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        if (priority.toLowerCase().equals("max")) {
            i_priority = Notification.PRIORITY_MAX;
        } else if (priority.toLowerCase().equals("min")) {
            i_priority = Notification.PRIORITY_MIN;
        }
    }
    return i_priority;
}
 
Example 2
Source File: NotificationHelper.java    From react-native-foreground-service with MIT License 4 votes vote down vote up
Notification buildNotification(Context context, Bundle notificationConfig) {
    if (notificationConfig == null) {
        Log.e("NotificationHelper", "buildNotification: invalid config");
        return null;
    }
    Class mainActivityClass = getMainActivityClass(context);
    if (mainActivityClass == null) {
        return null;
    }
    Intent notificationIntent = new Intent(context, mainActivityClass);
    PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, notificationIntent, 0);

    Notification.Builder notificationBuilder;

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        String channelId = notificationConfig.getString("channelId");
        if (channelId == null) {
            Log.e("NotificationHelper", "buildNotification: invalid channelId");
            return null;
        }
        notificationBuilder = new Notification.Builder(context, channelId);
    } else {
        notificationBuilder = new Notification.Builder(context);
    }

    int priorityInt = notificationConfig.containsKey("priority") ? notificationConfig.getInt("priority"): Notification.PRIORITY_HIGH;

    int priority;
    switch (priorityInt) {
        case 0:
            priority = Notification.PRIORITY_DEFAULT;
            break;
        case -1:
            priority = Notification.PRIORITY_LOW;
            break;
        case -2:
            priority = Notification.PRIORITY_MIN;
            break;
        case 1:
            priority = Notification.PRIORITY_HIGH;
            break;
        case 2:
            priority = Notification.PRIORITY_MAX;
            break;
        default:
            priority = Notification.PRIORITY_HIGH;
            break;

    }

    notificationBuilder.setContentTitle(notificationConfig.getString("title"))
            .setContentText(notificationConfig.getString("text"))
            .setPriority(priority)
            .setContentIntent(pendingIntent);

    String iconName = notificationConfig.getString("icon");
    if (iconName != null) {
        notificationBuilder.setSmallIcon(getResourceIdForResourceName(context, iconName));
    }

    return notificationBuilder.build();
}
 
Example 3
Source File: NotificationRecord.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
private int calculateImportance() {
    final Notification n = sbn.getNotification();
    int importance = getChannel().getImportance();
    int requestedImportance = IMPORTANCE_DEFAULT;

    // Migrate notification flags to scores
    if (0 != (n.flags & Notification.FLAG_HIGH_PRIORITY)) {
        n.priority = Notification.PRIORITY_MAX;
    }

    n.priority = NotificationManagerService.clamp(n.priority, Notification.PRIORITY_MIN,
            Notification.PRIORITY_MAX);
    switch (n.priority) {
        case Notification.PRIORITY_MIN:
            requestedImportance = IMPORTANCE_MIN;
            break;
        case Notification.PRIORITY_LOW:
            requestedImportance = IMPORTANCE_LOW;
            break;
        case Notification.PRIORITY_DEFAULT:
            requestedImportance = IMPORTANCE_DEFAULT;
            break;
        case Notification.PRIORITY_HIGH:
        case Notification.PRIORITY_MAX:
            requestedImportance = IMPORTANCE_HIGH;
            break;
    }
    stats.requestedImportance = requestedImportance;
    stats.isNoisy = mSound != null || mVibration != null;

    if (mPreChannelsNotification
            && (importance == IMPORTANCE_UNSPECIFIED
            || (getChannel().getUserLockedFields()
            & USER_LOCKED_IMPORTANCE) == 0)) {
        if (!stats.isNoisy && requestedImportance > IMPORTANCE_LOW) {
            requestedImportance = IMPORTANCE_LOW;
        }

        if (stats.isNoisy) {
            if (requestedImportance < IMPORTANCE_DEFAULT) {
                requestedImportance = IMPORTANCE_DEFAULT;
            }
        }

        if (n.fullScreenIntent != null) {
            requestedImportance = IMPORTANCE_HIGH;
        }
        importance = requestedImportance;
    }

    stats.naturalImportance = importance;
    return importance;
}
 
Example 4
Source File: OversecIntentService.java    From oversec with GNU General Public License v3.0 4 votes vote down vote up
public static Notification buildNotification(Context ctx, String packagename, boolean decryptOverlayIsShowing, boolean infoMode, boolean temporaryHidden) {

        Intent mainIntent = new Intent(ctx, OversecIntentService.class);
        mainIntent.setAction(temporaryHidden ? ACTION_TEMP_SHOW : ACTION_SHOW_CONFIG);
        mainIntent.putExtra(EXTRA_PACKAGE_NAME, packagename);

        PendingIntent pendingMainIntent = PendingIntent.getService(ctx, 0,
                mainIntent, PendingIntent.FLAG_UPDATE_CURRENT);

        Intent tempHideIntent = new Intent(ctx, OversecIntentService.class);
        tempHideIntent.setAction(ACTION_TEMP_HIDE);
        tempHideIntent.putExtra(EXTRA_PACKAGE_NAME, packagename);
        PendingIntent pendingTempHideIntent = PendingIntent.getService(ctx, 0,
                tempHideIntent, PendingIntent.FLAG_UPDATE_CURRENT);

        Intent tempShowIntent = new Intent(ctx, OversecIntentService.class);
        tempShowIntent.setAction(ACTION_TEMP_SHOW);
        tempShowIntent.putExtra(EXTRA_PACKAGE_NAME, packagename);
        PendingIntent pendingTempShowIntent = PendingIntent.getService(ctx, 0,
                tempShowIntent, PendingIntent.FLAG_UPDATE_CURRENT);

        Intent infoOnIntent = new Intent(ctx, OversecIntentService.class);
        infoOnIntent.setAction(ACTION_INFO_ON);
        PendingIntent pendingInfoOnIntent = PendingIntent.getService(ctx, 0,
                infoOnIntent, PendingIntent.FLAG_UPDATE_CURRENT);

        Intent infoOffIntent = new Intent(ctx, OversecIntentService.class);
        infoOffIntent.setAction(ACTION_INFO_OFF);
        PendingIntent pendingInfoOffIntent = PendingIntent.getService(ctx, 0,
                infoOffIntent, PendingIntent.FLAG_UPDATE_CURRENT);

        Intent stopIntent = new Intent(ctx, OversecIntentService.class);
        stopIntent.setAction(ACTION_STOPBOSS);
        PendingIntent pendingStopIntent = PendingIntent.getService(ctx, 0,
                stopIntent, PendingIntent.FLAG_UPDATE_CURRENT);

        NotificationCompat.Builder builder = new NotificationCompat.Builder(
                ctx)
                .setSmallIcon(R.drawable.ic_shutup_black_24dp)
                //  .setLargeIcon(largeIcon)
                .setColor(ContextCompat.getColor(ctx, io.oversec.one.crypto.R.color.colorPrimary))
                .setContentTitle(ctx.getString(temporaryHidden ? R.string.notification_title__hidden : R.string.notification_title__active))
                .setContentText(ctx.getString(temporaryHidden ? R.string.notification_body__hidden : R.string.notification_body__active))
                .setContentIntent(pendingMainIntent)

                .addAction(
                        Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP ?
                                R.drawable.ic_cancel_black_24dp : R.drawable.ic_cancel_white_24dp,
                        ctx.getString(R.string.notification_action_boss),
                        pendingStopIntent);
        if (!temporaryHidden) {
            builder.addAction(
                    Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP ?
                            R.drawable.ic_not_interested_black_24dp : R.drawable.ic_not_interested_white_24dp,
                    ctx.getString(decryptOverlayIsShowing ? R.string.notification_action_hide
                            : R.string.notification_action_show),
                    decryptOverlayIsShowing ? pendingTempHideIntent : pendingTempShowIntent);
        }
        if (decryptOverlayIsShowing && !temporaryHidden) {
            builder.addAction(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP ?
                            R.drawable.ic_info_outline_black_24dp : R.drawable.ic_info_outline_white_24dp,
                    ctx.getString(infoMode ? R.string.notification_action_unexplore
                            : R.string.notification_action_explore),
                    infoMode ? pendingInfoOffIntent : pendingInfoOnIntent);

        }

        Notification n = builder.build();
        if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) {
            n.visibility = Notification.VISIBILITY_SECRET;
        }
        n.priority = Notification.PRIORITY_MIN; //TODO: maybe make configurable
        return n;
    }