Example usage for android.app Notification CATEGORY_STATUS

List of usage examples for android.app Notification CATEGORY_STATUS

Introduction

In this page you can find the example usage for android.app Notification CATEGORY_STATUS.

Prototype

String CATEGORY_STATUS

To view the source code for android.app Notification CATEGORY_STATUS.

Click Source Link

Document

Notification category: ongoing information about device or contextual status.

Usage

From source file:eu.faircode.netguard.SinkholeService.java

private Notification getForegroundNotification() {
    Intent main = new Intent(this, ActivityMain.class);
    PendingIntent pi = PendingIntent.getActivity(this, 0, main, PendingIntent.FLAG_CANCEL_CURRENT);

    NotificationCompat.Builder notification = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.ic_security_white_24dp).setContentTitle(getString(R.string.app_name))
            .setContentText(getString(R.string.msg_started)).setContentIntent(pi)
            .setCategory(Notification.CATEGORY_STATUS).setVisibility(Notification.VISIBILITY_SECRET)
            .setColor(ContextCompat.getColor(this, R.color.colorPrimary)).setAutoCancel(true);

    return notification.build();
}

From source file:eu.faircode.netguard.SinkholeService.java

private void showDisabledNotification() {
    Intent main = new Intent(this, ActivityMain.class);
    PendingIntent pi = PendingIntent.getActivity(this, 0, main, PendingIntent.FLAG_CANCEL_CURRENT);

    NotificationCompat.Builder notification = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.ic_error_white_24dp).setContentTitle(getString(R.string.app_name))
            .setContentText(getString(R.string.msg_revoked)).setContentIntent(pi)
            .setCategory(Notification.CATEGORY_STATUS).setVisibility(Notification.VISIBILITY_SECRET)
            .setColor(ContextCompat.getColor(this, R.color.colorAccent)).setAutoCancel(true);

    NotificationManagerCompat.from(this).notify(NOTIFY_DISABLED, notification.build());
}

From source file:org.proninyaroslav.libretorrent.services.TorrentTaskService.java

private void makeFinishNotify(Torrent torrent) {
    if (torrent == null || notifyManager == null
            || !pref.getBoolean(getString(R.string.pref_key_torrent_finish_notify), true)) {
        return;//from  w  w  w.j  a v a 2s  .  c  om
    }

    NotificationCompat.Builder builder = new NotificationCompat.Builder(getApplicationContext())
            .setSmallIcon(R.drawable.ic_done_white_24dp)
            .setColor(ContextCompat.getColor(getApplicationContext(), R.color.primary))
            .setContentTitle(getString(R.string.torrent_finished_notify))
            .setTicker(getString(R.string.torrent_finished_notify)).setContentText(torrent.getName())
            .setWhen(System.currentTimeMillis());

    if (pref.getBoolean(getString(R.string.pref_key_play_sound_notify), true)) {
        Uri sound = Uri.parse(pref.getString(getString(R.string.pref_key_notify_sound),
                RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION).toString()));

        builder.setSound(sound);
    }

    if (pref.getBoolean(getString(R.string.pref_key_vibration_notify), true)) {
        /* TODO: Make the ability to customize vibration */
        long[] vibration = new long[] { 1000 }; /* ms */

        builder.setVibrate(vibration);
    }

    if (pref.getBoolean(getString(R.string.pref_key_led_indicator_notify), true)) {
        int color = pref.getInt(getString(R.string.pref_key_led_indicator_color_notify),
                ContextCompat.getColor(getApplicationContext(), R.color.primary));

        builder.setLights(color, 1000, 1000); /* ms */
    }

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        builder.setCategory(Notification.CATEGORY_STATUS);
    }

    notifyManager.notify(torrent.getId().hashCode(), builder.build());
}

From source file:org.proninyaroslav.libretorrent.services.TorrentTaskService.java

private synchronized void makeTorrentsMoveNotify() {
    /* TODO: Make the ability to customize the sound, LED and vibration */

    if (torrentsMoveTotal == null || torrentsMoveSuccess == null || torrentsMoveFailed == null
            || notifyManager == null) {/*ww  w.  ja  v a  2  s . co m*/
        return;
    }

    NotificationCompat.Builder builder = new NotificationCompat.Builder(getApplicationContext());

    String resultTemplate = getString(R.string.torrents_moved_content);
    int successfully = torrentsMoveSuccess.size();
    int failed = torrentsMoveFailed.size();

    builder.setContentTitle(getString(R.string.torrents_moved_title))
            .setTicker(getString(R.string.torrents_moved_title))
            .setContentText(String.format(resultTemplate, successfully, failed));

    builder.setSmallIcon(R.drawable.ic_folder_move_white_24dp).setAutoCancel(true)
            .setWhen(System.currentTimeMillis())
            .setStyle(makeTorrentsMoveInboxStyle(torrentsMoveSuccess, torrentsMoveFailed));

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        builder.setCategory(Notification.CATEGORY_STATUS);
    }

    notifyManager.notify(TORRENTS_MOVED_NOTIFICATION_ID, builder.build());

    torrentsMoveTotal = null;
    torrentsMoveSuccess = null;
    torrentsMoveFailed = null;
}

From source file:eu.faircode.adblocker.ServiceSinkhole.java

private Notification getEnforcingNotification(int allowed, int blocked, int hosts) {
    Intent main = new Intent(this, ActivityMain.class);
    PendingIntent pi = PendingIntent.getActivity(this, 0, main, PendingIntent.FLAG_UPDATE_CURRENT);

    TypedValue tv = new TypedValue();
    getTheme().resolveAttribute(R.attr.colorPrimary, tv, true);
    NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.ic_security_white_24dp).setContentTitle(getString(R.string.app_name))
            .setContentText(getString(R.string.msg_started)).setContentIntent(pi).setColor(tv.data)
            .setOngoing(true).setAutoCancel(false);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        builder.setCategory(Notification.CATEGORY_STATUS).setVisibility(Notification.VISIBILITY_SECRET)
                .setPriority(Notification.PRIORITY_MIN);
    }// w  w  w.j  av a 2  s .c  o  m

    if (allowed > 0 || blocked > 0 || hosts > 0) {
        NotificationCompat.BigTextStyle notification = new NotificationCompat.BigTextStyle(builder);
        notification.bigText(getString(R.string.msg_started));
        if (Util.isPlayStoreInstall(this))
            notification.setSummaryText(getString(R.string.msg_packages, allowed, blocked));
        else
            notification.setSummaryText(getString(R.string.msg_hosts, allowed, blocked, hosts));
        return notification.build();
    } else
        return builder.build();
}

From source file:eu.faircode.adblocker.ServiceSinkhole.java

private Notification getWaitingNotification() {
    Intent main = new Intent(this, ActivityMain.class);
    PendingIntent pi = PendingIntent.getActivity(this, 0, main, PendingIntent.FLAG_UPDATE_CURRENT);

    TypedValue tv = new TypedValue();
    getTheme().resolveAttribute(R.attr.colorPrimary, tv, true);
    NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.ic_security_white_24dp).setContentTitle(getString(R.string.app_name))
            .setContentText(getString(R.string.msg_waiting)).setContentIntent(pi).setColor(tv.data)
            .setOngoing(true).setAutoCancel(false);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        builder.setCategory(Notification.CATEGORY_STATUS).setVisibility(Notification.VISIBILITY_SECRET)
                .setPriority(Notification.PRIORITY_MIN);
    }//  w w  w . j  a  v  a  2 s .c  om

    return builder.build();
}

From source file:eu.faircode.adblocker.ServiceSinkhole.java

private void showDisabledNotification() {
    Intent main = new Intent(this, ActivityMain.class);
    PendingIntent pi = PendingIntent.getActivity(this, 0, main, PendingIntent.FLAG_UPDATE_CURRENT);

    TypedValue tv = new TypedValue();
    getTheme().resolveAttribute(R.attr.colorOff, tv, true);
    NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.ic_error_white_24dp).setContentTitle(getString(R.string.app_name))
            .setContentText(getString(R.string.msg_revoked)).setContentIntent(pi).setColor(tv.data)
            .setOngoing(false).setAutoCancel(true);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        builder.setCategory(Notification.CATEGORY_STATUS).setVisibility(Notification.VISIBILITY_SECRET);
    }/*from  w  w w  .  j a va 2s. co  m*/

    NotificationCompat.BigTextStyle notification = new NotificationCompat.BigTextStyle(builder);
    notification.bigText(getString(R.string.msg_revoked));

    NotificationManagerCompat.from(this).notify(NOTIFY_DISABLED, notification.build());
}

From source file:eu.faircode.adblocker.ServiceSinkhole.java

private void showAutoStartNotification() {
    Intent main = new Intent(this, ActivityMain.class);
    main.putExtra(ActivityMain.EXTRA_APPROVE, true);
    PendingIntent pi = PendingIntent.getActivity(this, NOTIFY_AUTOSTART, main,
            PendingIntent.FLAG_UPDATE_CURRENT);

    TypedValue tv = new TypedValue();
    getTheme().resolveAttribute(R.attr.colorOff, tv, true);
    NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.ic_error_white_24dp).setContentTitle(getString(R.string.app_name))
            .setContentText(getString(R.string.msg_autostart)).setContentIntent(pi).setColor(tv.data)
            .setOngoing(false).setAutoCancel(true);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        builder.setCategory(Notification.CATEGORY_STATUS).setVisibility(Notification.VISIBILITY_SECRET);
    }/*from   www  .  j  ava2  s .c o m*/

    NotificationCompat.BigTextStyle notification = new NotificationCompat.BigTextStyle(builder);
    notification.bigText(getString(R.string.msg_autostart));

    NotificationManagerCompat.from(this).notify(NOTIFY_AUTOSTART, notification.build());
}

From source file:eu.faircode.adblocker.ServiceSinkhole.java

private void showExitNotification(String reason) {
    Intent main = new Intent(this, ActivityMain.class);
    PendingIntent pi = PendingIntent.getActivity(this, 0, main, PendingIntent.FLAG_UPDATE_CURRENT);

    TypedValue tv = new TypedValue();
    getTheme().resolveAttribute(R.attr.colorOff, tv, true);
    NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.ic_error_white_24dp).setContentTitle(getString(R.string.app_name))
            .setContentText(getString(R.string.msg_error)).setContentIntent(pi).setColor(tv.data)
            .setOngoing(false).setAutoCancel(true);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        builder.setCategory(Notification.CATEGORY_STATUS).setVisibility(Notification.VISIBILITY_SECRET);
    }//  w w w  . jav  a  2  s. c om

    NotificationCompat.BigTextStyle notification = new NotificationCompat.BigTextStyle(builder);
    notification.bigText(getString(R.string.msg_error));
    notification.setSummaryText(reason);

    NotificationManagerCompat.from(this).notify(NOTIFY_EXIT, notification.build());
}

From source file:eu.faircode.adblocker.ServiceSinkhole.java

private void showErrorNotification(int error, String message) {
    Intent main = new Intent(this, ActivityMain.class);
    main.putExtra(ActivityMain.EXTRA_LOGCAT, true);
    PendingIntent pi = PendingIntent.getActivity(this, NOTIFY_ERROR, main, PendingIntent.FLAG_UPDATE_CURRENT);

    TypedValue tv = new TypedValue();
    getTheme().resolveAttribute(R.attr.colorOff, tv, true);
    NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.ic_error_white_24dp).setContentTitle(getString(R.string.app_name))
            .setContentText(message).setContentIntent(pi).setNumber(error).setColor(tv.data).setOngoing(false)
            .setAutoCancel(true);/*from   www.  j  a  va2  s  .  com*/

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        builder.setCategory(Notification.CATEGORY_STATUS).setVisibility(Notification.VISIBILITY_SECRET);
    }

    NotificationCompat.BigTextStyle notification = new NotificationCompat.BigTextStyle(builder);
    notification.bigText(message);

    NotificationManagerCompat.from(this).notify(error + 100, notification.build());
}