Example usage for android.app Notification FLAG_NO_CLEAR

List of usage examples for android.app Notification FLAG_NO_CLEAR

Introduction

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

Prototype

int FLAG_NO_CLEAR

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

Click Source Link

Document

Bit to be bitwise-ored into the #flags field that should be set if the notification should not be canceled when the user clicks the Clear all button.

Usage

From source file:com.andrewreitz.encryptedcamera.di.module.AndroidModule.java

@Provides
@Singleton/*from  ww  w.  ja  v  a2 s .c o m*/
@UnlockNotification
Notification provideUnlockNotification() {
    Notification notification = new NotificationCompat.Builder(application) //
            .setContentTitle(application.getString(R.string.app_name)) //
            .setContentText(application.getString(R.string.images_unencryped_message)) //
            .setContentIntent(PendingIntent.getActivity(application, 0,
                    new Intent(application, SettingsActivity.class), 0)) //
            .setSmallIcon(R.drawable.ic_unlocked) //
            .build();

    notification.flags |= Notification.FLAG_NO_CLEAR;

    return notification;
}

From source file:com.oasisfeng.nevo.StatusBarNotificationEvo.java

@Override
public boolean isClearable() {
    try {/*from ww  w .ja v  a2s.c  om*/
        final int flags = notification().getFlags();
        return (flags & (Notification.FLAG_ONGOING_EVENT | Notification.FLAG_NO_CLEAR)) == 0;
    } catch (final RemoteException e) {
        throw new IllegalStateException(e);
    }
}

From source file:com.evandroid.musica.services.BatchDownloaderService.java

private void updateProgress() {
    NotificationManager manager = ((NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE));
    if (count < total) {
        NotificationCompat.Builder notifBuilder = new NotificationCompat.Builder(this);
        notifBuilder.setSmallIcon(android.R.drawable.stat_sys_download)
                .setContentTitle(getString(R.string.app_name))
                .setContentText(String.format(getString(R.string.dl_progress), count, total))
                .setProgress(total, count, false).setShowWhen(false);
        Notification notif = notifBuilder.build();
        notif.flags |= Notification.FLAG_NO_CLEAR | Notification.FLAG_ONGOING_EVENT;
        if (count == 0)
            startForeground(1, notif);/* w ww. j  a  v  a  2  s.c  o  m*/
        else
            manager.notify(1, notif);
    } else {
        stopForeground(true);
        Intent refreshIntent = new Intent("com.geecko.QuickLyric.updateDBList");
        PendingIntent pendingIntent = PendingIntent.getActivity(getBaseContext(), 4, refreshIntent,
                PendingIntent.FLAG_ONE_SHOT);
        String text = getResources().getQuantityString(R.plurals.dl_finished_desc, successCount, successCount);
        NotificationCompat.Builder notifBuilder = new NotificationCompat.Builder(this);
        notifBuilder.setSmallIcon(android.R.drawable.stat_sys_download_done);
        notifBuilder.setContentIntent(pendingIntent);
        notifBuilder.setContentTitle(getString(R.string.dl_finished));
        notifBuilder.setContentText(text);
        Notification notif = notifBuilder.build();
        notif.flags |= Notification.FLAG_AUTO_CANCEL;
        manager.notify(1, notif);
        stopSelf();
    }
}

From source file:step.StepService.java

@Override
public int onStartCommand(Intent intent, int flags, int startId) {

    if (Build.VERSION.SDK_INT < 18) {

        NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this)
                .setSmallIcon(R.mipmap.step_launcher).setContentTitle("??")
                .setContentText("??");

        Notification notification = mBuilder.build();

        PendingIntent contentIntent = PendingIntent.getActivity(this, 0,
                new Intent(this, StepCountActivity.class), PendingIntent.FLAG_UPDATE_CURRENT);

        notification.flags |= Notification.FLAG_ONGOING_EVENT | Notification.FLAG_NO_CLEAR;
        mBuilder.setContentIntent(contentIntent);
        startForeground(GRAY_SERVICE_ID, notification);//API < 18 ??Notification
    } else {/*from ww  w  . j ava  2  s.  c om*/
        Intent innerIntent = new Intent(this, GrayInnerService.class);
        startService(innerIntent);
        startForeground(GRAY_SERVICE_ID, new Notification());
    }

    return Service.START_STICKY;
}

From source file:at.aec.solutions.checkmkagent.AgentService.java

@Override
public void onCreate() {
    super.onCreate();
    Log.v(TAG, "onCreate");

    PowerManager powerManager = (PowerManager) getSystemService(POWER_SERVICE);
    m_wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "MyWakelockTag");
    m_wakeLock.acquire();//  ww  w  . jav  a  2  s .c om

    //Copy busybox binary to app directory
    if (!PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).getBoolean("bbinstalled",
            false)) {
        PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).edit()
                .putBoolean("bbinstalled", true).commit();

        // There is also String[] Build.SUPPORTED_ABIS from API 21 on and
        // before String Build.CPU_ABI String Build.CPU_ABI2, maybe i should investigate there
        String arch = System.getProperty("os.arch");
        Log.v(TAG, arch);
        if (arch.equals("armv7l")) {
            copyAsset(getAssets(), "bbb/busybox", getApplicationInfo().dataDir + "/busybox");
        }
        if (arch.equals("i686")) {
            copyAsset(getAssets(), "bbb/busybox-i686", getApplicationInfo().dataDir + "/busybox");
        }

        //         copyAsset(getAssets(), "bbb/busybox-x86_64", getApplicationInfo().dataDir+"/busybox-x86_64");
        changeBusyboxPermission();
    }

    socketServerThread = new Thread(new SocketServerThread());
    socketServerThread.setName("CheckMK-Agent ServerThread");
    socketServerThread.start();

    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.ic_launcher).setContentTitle("CheckMK Agent started.")
            .setContentText("Listening on Port " + SERVERPORT + ". Tap to configure.");

    Intent resultIntent = new Intent(this, ConfigureActivity.class);

    TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
    // Adds the back stack for the Intent (but not the Intent itself)
    stackBuilder.addParentStack(ConfigureActivity.class);
    // Adds the Intent that starts the Activity to the top of the stack
    stackBuilder.addNextIntent(resultIntent);
    PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);

    mBuilder.setContentIntent(resultPendingIntent);
    NotificationManager mNotificationManager = (NotificationManager) getSystemService(
            Context.NOTIFICATION_SERVICE);
    // mId allows you to update the notification later on.
    Notification notify = mBuilder.build();
    notify.flags |= Notification.FLAG_NO_CLEAR;

    mNotificationManager.notify(mId, notify);
}

From source file:com.florianmski.tracktoid.trakt.tasks.get.UpdateShowsTask.java

private void createNotification() {
    notification = new Notification(R.drawable.ab_icon_refresh, "Refreshing...", System.currentTimeMillis());
    nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
    contentView = new RemoteViews(context.getPackageName(), R.layout.notification_progress);
    notification.contentView = contentView;

    Intent notificationIntent = new Intent(context, MyShowsActivity.class);
    notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, 0);
    notification.contentIntent = contentIntent;
    notification.flags = Notification.FLAG_NO_CLEAR;

    nm.notify(NOTIFICATION_ID, notification);
}

From source file:com.example.samples.mp3player.Mp3PlayerService.java

/**
 * Show a notification while this service is running.
 *//*from  w w  w.  j a va2s .co  m*/
private Notification buildMp3PlayerNotification() {
    CharSequence title = getText(R.string.mp3player_service_started);
    CharSequence text = getText(R.string.mp3player_service_label);

    Intent i = new Intent(this, Mp3Player.class);
    i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);

    // The PendingIntent to launch our activity if the user selects this notification
    PendingIntent contentIntent = PendingIntent.getActivity(this, 0, i, 0);

    NotificationCompat.InboxStyle style = new NotificationCompat.InboxStyle()
            .addLine("M.Twain (Google+) Haiku is more than a cert...").addLine("M.Twain Reminder")
            .addLine("M.Twain Lunch?").addLine("M.Twain Revised Specs").addLine("M.Twain ")
            .addLine("Google Play Celebrate 25 billion apps with Goo..")
            .addLine("Stack Exchange StackOverflow weekly Newsl...").setBigContentTitle("6 new message")
            .setSummaryText("mtwain@android.com");

    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.stat_sample).setContentTitle(title).setContentText(text);
    //.setContentIntent(contentIntent);

    Notification noti = mBuilder.build();

    RemoteViews expandedView = new RemoteViews(this.getPackageName(), R.layout.mp3player_notification);
    expandedView.setOnClickPendingIntent(R.id.noti_image, contentIntent);
    expandedView.setOnClickPendingIntent(R.id.noti_button_play, contentIntent);

    noti.bigContentView = expandedView;
    noti.flags |= Notification.FLAG_NO_CLEAR;

    return noti;
}

From source file:pct.droid.base.torrent.TorrentService.java

public void startForeground() {
    Timber.d("startForeground");
    if (mInForeground)
        return;/*from  ww w. j a v a 2  s. co m*/

    Intent notificationIntent = new Intent(this, mCurrentActivityClass);
    notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);

    NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
            .setSmallIcon(pct.droid.base.R.drawable.ic_notif_logo)
            .setContentTitle("Popcorn Time - " + getString(pct.droid.base.R.string.running))
            .setContentText(getString(R.string.tap_to_resume)).setOngoing(true).setContentIntent(pendingIntent)
            .setCategory(NotificationCompat.CATEGORY_SERVICE);

    Notification notification = builder.build();
    notification.flags = Notification.FLAG_ONGOING_EVENT | Notification.FLAG_NO_CLEAR;

    startForeground(mId, notification);
    mInForeground = true;
}

From source file:com.waz.zclient.controllers.notifications.NotificationsController.java

private void showCallNotification(ActiveChannel activeChannel, int id, boolean noClear) {
    Notification notification = getCallNotification(activeChannel);
    notification.priority = Notification.PRIORITY_MAX;
    if (noClear) {
        notification.flags |= Notification.FLAG_NO_CLEAR;
    }/*from w w  w.  j a va  2 s  .c  om*/
    notificationManager.notify(id, notification);
}

From source file:co.vanir.indecentxposure.IndecentXposure.java

@TargetApi(Build.VERSION_CODES.ECLAIR)
private static void notify(final Context context, final Notification notification, boolean sticky) {
    if (sticky)//w  ww.  ja va2  s  .  c o  m
        notification.flags |= Notification.FLAG_NO_CLEAR;
    else
        notification.flags &= ~Notification.FLAG_NO_CLEAR;

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ECLAIR) {
        ((NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE)).notify(NOTIFICATION_TAG,
                0, notification);
    } else {
        ((NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE))
                .notify(NOTIFICATION_TAG.hashCode(), notification);
    }
}