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.cyanogenmod.settings.device.LtoDownloadService.java

private void showDownloadNotification(int progress, boolean indeterminate) {
    // Create a notification
    Bitmap largeIcon = (((BitmapDrawable) getResources()
            .getDrawable(com.cyanogenmod.settings.device.R.drawable.stat_sys_download)).getBitmap());
    String title = getString(R.string.lto_downloading_data_notification);
    Notification.Builder builder = new Notification.Builder(this).setContentTitle(title)
            .setSmallIcon(android.R.drawable.stat_sys_download).setLargeIcon(largeIcon)
            .setProgress(100, progress, indeterminate).setWhen(0);
    Notification notification = builder.build();
    notification.tickerText = title;/*from w ww .ja  va 2  s. c  o  m*/
    notification.flags = Notification.FLAG_NO_CLEAR;
    mNotificationManager.notify(NOTIFICATION_ID, notification);
}

From source file:com.elixsr.portforwarder.forwarding.ForwardingService.java

/**
 * Construct a notification/*from   www.  ja  v  a 2 s .com*/
 */
private void showForwardingEnabledNotification() {
    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.ic_fwd_24dp).setContentTitle("Port Forwarding Active")
            .setContentText("Touch to disable");

    mBuilder.setColor(ContextCompat.getColor(this, R.color.colorPrimaryDark));

    // Creates an explicit intent for an Activity in your app
    Intent resultIntent = new Intent(this, MainActivity.class);

    // The stack builder object will contain an artificial back stack for the
    // started Activity.
    // This ensures that navigating backward from the Activity leads out of
    // your application to the Home screen.
    TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);

    // Adds the back stack for the Intent (but not the Intent itself)
    stackBuilder.addParentStack(MainActivity.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);

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

    // mId allows you to update the notification later on.
    mNotificationManager.notify(NOTIFICATION_ID, notification);
}

From source file:name.setup.dance.StepService.java

/**
 * Show a notification while this service is running.
 *///from  www . j  av  a2 s. c o m
private void showNotification() {
    CharSequence text = getText(R.string.app_name);
    Notification notification = new Notification(R.drawable.ic_notification, null, System.currentTimeMillis());
    notification.flags = Notification.FLAG_NO_CLEAR | Notification.FLAG_ONGOING_EVENT;
    Intent DanceStepAppIntent = new Intent();
    DanceStepAppIntent.setComponent(new ComponentName(this, DanceStepApp.class));
    DanceStepAppIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    PendingIntent contentIntent = PendingIntent.getActivity(this, 0, DanceStepAppIntent, 0);
    notification.setLatestEventInfo(this, text, getText(R.string.notification_subtitle), contentIntent);

    mNM.notify(R.string.app_name, notification);
}

From source file:com.newcell.calltext.service.SipNotifications.java

public void showNotificationForCall(SipCallSession callInfo) {
    // This is the pending call notification
    // int icon = R.drawable.ic_incall_ongoing;
    @SuppressWarnings("deprecation")
    int icon = android.R.drawable.stat_sys_phone_call;
    CharSequence tickerText = context.getText(R.string.ongoing_call);
    long when = System.currentTimeMillis();

    if (inCallNotification == null) {
        inCallNotification = new NotificationCompat.Builder(context).setSmallIcon(icon).setTicker(tickerText)
                .setWhen(when).setOngoing(true);
    }/*w w w  .  j  ava  2 s.c  o m*/

    Intent notificationIntent = SipService.buildCallUiIntent(context, callInfo);
    PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent,
            PendingIntent.FLAG_CANCEL_CURRENT);
    //        PendingIntent endCallIntent = PendingIntent.getActivity(context, 0, notificationIntent, IOnCallActionTrigger.TERMINATE_CALL);
    //        PendingIntent speakerOnIntent = PendingIntent.getActivity(context, 0, notificationIntent, IOnCallActionTrigger.SPEAKER_ON);
    //        PendingIntent speakerOffIntent = PendingIntent.getActivity(context, 0, notificationIntent, IOnCallActionTrigger.SPEAKER_OFF);

    /*
       * Change in-call notification here
       */
    inCallNotification.setContentTitle(context.getText(R.string.ongoing_call));
    //        inCallNotification.setContentTitle(formatNotificationTitle(R.string.ongoing_call, callInfo.getAccId())); // old version

    inCallNotification.setContentText(SipUri.getDisplayedSimpleContact(callInfo.getRemoteContact()));
    //        inCallNotification.setContentText(formatRemoteContactString(callInfo.getRemoteContact())); // old version
    /*
     * 
     */
    inCallNotification.setContentIntent(contentIntent);
    // End call/Speaker buttons on notification

    //      inCallNotification.addAction(R.drawable.ic_lockscreen_decline_normal, "", endCallIntent);
    //       inCallNotification.addAction(R.drawable.ic_speaker_dark, "", speakerOnIntent);

    Notification notification = inCallNotification.build();
    notification.flags |= Notification.FLAG_NO_CLEAR;
    notificationManager.notify(CALL_NOTIF_ID, notification);
}

From source file:com.roamprocess1.roaming4world.service.SipNotifications.java

public void showNotificationForCall(SipCallSession callInfo) {
    // This is the pending call notification
    // int icon = R.drawable.ic_incall_ongoing;
    @SuppressWarnings("deprecation")
    int icon = android.R.drawable.stat_sys_phone_call;
    CharSequence tickerText = context.getText(R.string.ongoing_call);

    System.out.println("SipNotifications tickerText" + tickerText);
    long when = System.currentTimeMillis();

    if (inCallNotification == null) {
        inCallNotification = new NotificationCompat.Builder(context);
        inCallNotification.setSmallIcon(icon);
        inCallNotification.setTicker(tickerText);
        inCallNotification.setWhen(when);
        inCallNotification.setOngoing(true);
    }//from  www.  j  av  a  2 s  .c  o  m

    System.out.println("callInfo.getRemoteContact() ===" + callInfo.getRemoteContact());
    String[] parts = callInfo.getRemoteContact().split("@");

    String part1 = parts[0]; // 004
    String[] part3 = part1.split(":");
    System.out.println("part3==" + part3);
    String part4 = part3[0];
    System.out.println("part4 ==" + part4);
    String part5 = part3[1];
    System.out.println(" in side part5 ==" + part5);
    if (part5.startsWith("011")) {
        part5 = part5.substring(3);
    }
    System.out.println("showNotificationForCall");

    Intent notificationIntent = SipService.buildCallUiIntent(context, callInfo);
    PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, 0);

    inCallNotification.setContentTitle(formatNotificationTitle(R.string.ongoing_call, callInfo.getAccId()));
    inCallNotification.setContentText(formatRemoteContactString(part5));
    inCallNotification.setContentIntent(contentIntent);

    Notification notification = inCallNotification.build();
    notification.flags |= Notification.FLAG_NO_CLEAR;
    notificationManager.notify(CALL_NOTIF_ID, notification);
}

From source file:org.deviceconnect.android.deviceplugin.host.camera.CameraOverlay.java

/**
 * Notification??.// w ww. j  a  v a 2 s . c  om
 */
private void sendNotification() {
    PendingIntent contentIntent = createPendingIntent();
    Notification notification = createNotification(contentIntent);
    notification.flags = Notification.FLAG_NO_CLEAR;
    NotificationManager manager = (NotificationManager) mContext.getSystemService(Service.NOTIFICATION_SERVICE);
    manager.cancel(NOTIFICATION_ID);
    manager.notify(NOTIFICATION_ID, notification);
}

From source file:fi.hut.soberit.sensors.services.BatchDataUploadService.java

private void showBatchUploadNotification(String text, int progress, boolean noClear) {
    if (notification == null) {
        notification = new Notification(R.drawable.ic_icon_export, text, System.currentTimeMillis());

        // final Intent appIntent = new Intent(this, SIDE.class);
        final PendingIntent contentIntent = PendingIntent.getActivity(this, 0, null, 0);

        notification.setLatestEventInfo(this, getString(R.string.app_name), text, contentIntent);

        RemoteViews contentView = new RemoteViews(getPackageName(), R.layout.batch_upload_notification_layout);
        contentView.setImageViewResource(R.id.status_icon, R.drawable.ic_icon_export);
        notification.contentView = contentView;
    }/*w  w w  . j  a  v  a  2s.  co m*/

    notification.contentView.setTextViewText(R.id.status_text, text);
    notification.contentView.setProgressBar(R.id.progress_bar, MAX_PROGRESS, progress, false);

    if (noClear) {
        notification.flags |= Notification.FLAG_NO_CLEAR | Notification.FLAG_ONGOING_EVENT;
    } else {
        notificationManager.cancel(R.id.batch_upload);

        notification.flags ^= Notification.FLAG_NO_CLEAR | Notification.FLAG_ONGOING_EVENT;
    }
    notificationManager.notify(R.id.batch_upload, notification);
}

From source file:com.sonetel.service.SipNotifications.java

public void showNotificationForCall(SipCallSession callInfo) {
    // This is the pending call notification
    // int icon = R.drawable.ic_incall_ongoing;
    @SuppressWarnings("deprecation")
    int icon = android.R.drawable.stat_sys_phone_call;
    CharSequence tickerText = context.getText(R.string.ongoing_call);
    long when = System.currentTimeMillis();

    if (inCallNotification == null) {
        inCallNotification = new NotificationCompat.Builder(context);
        inCallNotification.setSmallIcon(icon);
        inCallNotification.setTicker(tickerText);
        inCallNotification.setWhen(when);
        inCallNotification.setOngoing(true);
    }//from  w w w . j  a  va 2  s.c  om

    Intent notificationIntent = SipService.buildCallUiIntent(context, callInfo);
    PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent,
            PendingIntent.FLAG_CANCEL_CURRENT);

    inCallNotification.setContentTitle(formatNotificationTitle(R.string.ongoing_call, callInfo.getAccId()));
    inCallNotification.setContentText(formatRemoteContactString(callInfo.getRemoteContact()));
    inCallNotification.setContentIntent(contentIntent);

    Notification notification = inCallNotification.getNotification();
    notification.flags |= Notification.FLAG_NO_CLEAR;
    notificationManager.notify(CALL_NOTIF_ID, notification);
}

From source file:com.ubergeek42.WeechatAndroid.service.RelayService.java

@Override
public void onHighlight(String bufferName, String message) {
    Intent i = new Intent(this, WeechatActivity.class);
    i.putExtra("buffer", bufferName);
    PendingIntent contentIntent = PendingIntent.getActivity(this, 0, i, PendingIntent.FLAG_UPDATE_CURRENT);

    NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
    builder.setContentIntent(contentIntent).setSmallIcon(R.drawable.ic_notification)
            .setContentTitle(getString(R.string.app_version)).setContentText(message).setTicker(message)
            .setWhen(System.currentTimeMillis());

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

    // Default notification sound if enabled
    if (prefs.getBoolean("notification_sounds", false)) {
        notification.defaults |= Notification.DEFAULT_SOUND;
    }/*from  w ww . ja  v  a  2  s .  c  o  m*/

    notificationManger.notify(NOTIFICATION_ID, notification);
}

From source file:com.dmbstream.android.util.Util.java

public static void showPlayingNotification(final Context context, final DownloadServiceImpl downloadService,
        Handler handler, Track song) {

    // Use the same text for the ticker and the expanded notification
    String title = song.title;//from   w  ww. ja  va2  s. c o  m
    String text = song.artist;

    // Set the icon, scrolling text and timestamp
    final Notification notification = new Notification(R.drawable.notify_playing, title,
            System.currentTimeMillis());
    notification.flags |= Notification.FLAG_NO_CLEAR | Notification.FLAG_ONGOING_EVENT;

    RemoteViews contentView = new RemoteViews(context.getPackageName(), R.layout.partial_notification);

    // set the text for the notifications
    contentView.setTextViewText(R.id.notification_title, title);
    contentView.setTextViewText(R.id.notification_artist, text);

    Pair<Integer, Integer> colors = getNotificationTextColors(context);
    if (colors.getFirst() != null) {
        contentView.setTextColor(R.id.notification_title, colors.getFirst());
    }
    if (colors.getSecond() != null) {
        contentView.setTextColor(R.id.notification_artist, colors.getSecond());
    }

    notification.contentView = contentView;

    // Send them to the main menu when if they click the notification
    // TODO: Send them to the concert, playlist, compilation details or chat page?
    Intent notificationIntent = new Intent(context, MainMenuActivity.class);
    notification.contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, 0);

    // Send the notification and put the service in the foreground.
    handler.post(new Runnable() {
        @Override
        public void run() {
            startForeground(downloadService, Constants.NOTIFICATION_ID_PLAYING, notification);
        }
    });

    // Update widget
    DmbstreamAppWidgetProvider.getInstance().notifyChange(context, downloadService, true);
}