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.f2prateek.dfg.core.GenerateMultipleFramesService.java

public void notifyStarting() {
    Intent nullIntent = new Intent(this, MainActivity.class);
    nullIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    notificationBuilder = new NotificationCompat.Builder(this)
            .setTicker(resources.getString(R.string.screenshot_saving_ticker))
            .setContentTitle(resources.getString(R.string.screenshot_saving_title))
            .setSmallIcon(R.drawable.ic_stat_app_notification)
            .setContentIntent(PendingIntent.getActivity(this, 0, nullIntent, 0)).setProgress(0, 0, true)
            .setWhen(System.currentTimeMillis());

    Notification n = notificationBuilder.build();
    n.flags |= Notification.FLAG_NO_CLEAR;
    notificationManager.notify(DFG_NOTIFICATION_ID, n);
}

From source file:github.popeen.dsub.util.Notifications.java

public static void showPlayingNotification(final Context context, final DownloadService downloadService,
        final Handler handler, MusicDirectory.Entry song) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        getPlayingNotificationChannel(context);
    }//from ww  w.java  2  s  . com

    // Set the icon, scrolling text and timestamp
    final Notification notification = new NotificationCompat.Builder(context)
            .setSmallIcon(R.drawable.stat_notify_playing).setTicker(song.getTitle())
            .setWhen(System.currentTimeMillis()).setChannelId("now-playing-channel").build();

    final boolean playing = downloadService.getPlayerState() == PlayerState.STARTED;
    if (playing) {
        notification.flags |= Notification.FLAG_NO_CLEAR | Notification.FLAG_ONGOING_EVENT;
    }
    boolean remote = downloadService.isRemoteEnabled();
    boolean isSingle = downloadService.isCurrentPlayingSingle();
    boolean shouldFastForward = true;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        RemoteViews expandedContentView = new RemoteViews(context.getPackageName(),
                R.layout.notification_expanded);
        setupViews(expandedContentView, context, song, true, playing, remote, isSingle, shouldFastForward);
        notification.bigContentView = expandedContentView;
        notification.priority = Notification.PRIORITY_HIGH;
    }
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        notification.visibility = Notification.VISIBILITY_PUBLIC;

        if (Util.getPreferences(context).getBoolean(Constants.PREFERENCES_KEY_HEADS_UP_NOTIFICATION, false)
                && !UpdateView.hasActiveActivity()) {
            notification.vibrate = new long[0];
        }
    }

    RemoteViews smallContentView = new RemoteViews(context.getPackageName(), R.layout.notification);
    setupViews(smallContentView, context, song, false, playing, remote, isSingle, shouldFastForward);
    notification.contentView = smallContentView;

    Intent notificationIntent = new Intent(context, SubsonicFragmentActivity.class);
    notificationIntent.putExtra(Constants.INTENT_EXTRA_NAME_DOWNLOAD, true);

    notificationIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    notification.contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, 0);

    playShowing = true;
    if (downloadForeground && downloadShowing) {
        downloadForeground = false;
        handler.post(new Runnable() {
            @Override
            public void run() {
                stopForeground(downloadService, true);
                showDownloadingNotification(context, downloadService, handler,
                        downloadService.getCurrentDownloading(),
                        downloadService.getBackgroundDownloads().size());

                try {
                    startForeground(downloadService, NOTIFICATION_ID_PLAYING, notification);
                } catch (Exception e) {
                    Log.e(TAG, "Failed to start notifications after stopping foreground download");
                }
            }
        });
    } else {
        handler.post(new Runnable() {
            @Override
            public void run() {

                if (playing) {
                    try {
                        startForeground(downloadService, NOTIFICATION_ID_PLAYING, notification);
                    } catch (Exception e) {
                        Log.e(TAG, "Failed to start notifications while playing");
                    }
                } else {
                    playShowing = false;
                    persistentPlayingShowing = true;
                    NotificationManager notificationManager = (NotificationManager) context
                            .getSystemService(Context.NOTIFICATION_SERVICE);
                    stopForeground(downloadService, false);

                    try {
                        notificationManager.notify(NOTIFICATION_ID_PLAYING, notification);
                    } catch (Exception e) {
                        Log.e(TAG, "Failed to start notifications while paused");
                    }
                }
            }
        });
    }

    // Update widget
    DSubWidgetProvider.notifyInstances(context, downloadService, playing);
}

From source file:com.sspai.dkjt.service.GenerateMultipleFramesService.java

public void notifyStarting() {
    Intent nullIntent = new Intent(this, MainActivity.class);
    nullIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    notificationBuilder = new NotificationCompat.Builder(this)
            .setTicker(resources.getString(R.string.screenshot_saving_ticker))
            .setContentTitle(resources.getString(R.string.screenshot_saving_title))
            .setSmallIcon(R.drawable.ic_actionbar_logo)
            .setContentIntent(PendingIntent.getActivity(this, 0, nullIntent, 0)).setProgress(0, 0, true)
            .setWhen(System.currentTimeMillis());

    Notification n = notificationBuilder.build();
    n.flags |= Notification.FLAG_NO_CLEAR;
    notificationManager.notify(DFG_NOTIFICATION_ID, n);
}

From source file:com.ademsha.appnotifico.NotificationHelper.java

public static void notifyForForegroundService(final Service service,
        final PreparedNotification preparedNotification) {

    final NotificationCompat.Builder builder = new NotificationCompat.Builder(preparedNotification.getContext())
            .setPriority(NotificationCompat.PRIORITY_MIN).setOngoing(true).setAutoCancel(false)
            .setOnlyAlertOnce(true);//from  w ww. j  a va2 s .c o  m

    if (preparedNotification.getPendingIntentForActivity() != null) {
        builder.setContentIntent(preparedNotification.getPendingIntentForService());
    }

    builder.setContentTitle(preparedNotification.getTitle());
    builder.setContentText(preparedNotification.getText());

    if (preparedNotification.getLargeIcon() != null) {
        builder.setLargeIcon(preparedNotification.getLargeIcon());
    }

    if (preparedNotification.getSmallIcon() > 0) {
        builder.setSmallIcon(preparedNotification.getSmallIcon());
    }

    builder.setTicker(preparedNotification.getTicker());

    if (!preparedNotification.getExpanded().equals("")
            && !preparedNotification.getExpandedSummary().equals("")) {
        builder.setStyle(new NotificationCompat.BigTextStyle().bigText(preparedNotification.getExpanded())
                .setBigContentTitle(preparedNotification.getTitle())
                .setSummaryText(preparedNotification.getExpandedSummary()));
    }

    if (preparedNotification.getPendingIntentForActivity() != null) {
        builder.setContentIntent(preparedNotification.getPendingIntentForActivity());
    }

    Notification notification;
    notification = builder.build();
    notification.flags |= Notification.FLAG_ONGOING_EVENT | Notification.FLAG_FOREGROUND_SERVICE
            | Notification.FLAG_NO_CLEAR;
    service.startForeground(10000, notification);
}

From source file:org.openplans.rcavl.LocationService.java

public void realStart(Intent intent) {
    String url = intent.getStringExtra("pingUrl");
    String email = intent.getStringExtra("email");
    String password = intent.getStringExtra("password");
    pingInterval = intent.getIntExtra("pingInterval", 60);

    Notification notification = new Notification(R.drawable.icon, "Ridepilot Mobile",
            System.currentTimeMillis());
    Intent appIntent = new Intent(this, RCAVL.class);

    appIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);

    PendingIntent pi = PendingIntent.getActivity(this, 0, appIntent, 0);

    notification.setLatestEventInfo(this, "Ridepilot Mobile", "connected", pi);
    notification.flags |= Notification.FLAG_NO_CLEAR;
    startForeground(66786, notification);

    thread = new LocationServiceThread(url, email, password);
    new Thread(thread).start();
}

From source file:de.unistuttgart.ipvs.pmp.service.ServiceNotification.java

/**
 * @param context/*  w w w  .  java  2s.c om*/
 * @return a new {@link Notification} for the {@link PMPService}
 */
private static Notification makeNotification(Context context) {

    PendingIntent pi = PendingIntent.getActivity(context.getApplicationContext(), 0,
            new Intent(context, ActivityMain.class), 0);
    NotificationCompat.Builder builder = new NotificationCompat.Builder(PMPApplication.getContext());
    Notification notification = builder.setContentIntent(pi).setSmallIcon(R.drawable.icon)
            .setTicker(context.getString(R.string.svc_nfc_title)).setWhen(System.currentTimeMillis())
            .setOngoing(true).setDefaults(Notification.FLAG_NO_CLEAR)
            .setContentTitle(context.getString(R.string.svc_nfc_extended_title))
            .setContentText(context.getString(R.string.svc_nfc_description)).build();
    return notification;
}

From source file:org.ado.minesync.gui.notification.MineSyncNotification.java

public void buildNotification(boolean syncActive, boolean startForeground) {
    notificationTemplate = new RemoteViews(service.getPackageName(), R.layout.layout_notification);
    PendingIntent pendingIntent = getMainPendingIntent();
    notification = new NotificationCompat.Builder(service.getApplicationContext())
            .setTicker(getResourceText(R.string.label_notification_service_title))
            .setContent(notificationTemplate).setSmallIcon(android.R.color.transparent)
            .setContentIntent(pendingIntent).setPriority(NotificationCompat.PRIORITY_MIN).setOngoing(true)
            .setAutoCancel(false).setColor(getColor(R.color.dropbox_blue)).build();
    notification.flags |= Notification.FLAG_NO_CLEAR;
    initActions(syncActive);//from  w w w . j  av  a  2  s.c o m
    /*        if (startForeground) {
    service.startForeground(NOTIFICATION_SYNC, notification);
            }*/
}

From source file:com.adityarathi.muo.services.BuildMusicLibraryService.java

@Override
public void onProgressUpdate(AsyncBuildLibraryTask task, String mCurrentTask, int overallProgress,
        int maxProgress, boolean mediaStoreTransferDone) {
    mBuilder = new NotificationCompat.Builder(mContext);
    mBuilder.setSmallIcon(R.mipmap.ic_launcher);
    mBuilder.setContentTitle(mCurrentTask);
    mBuilder.setTicker(mCurrentTask);/*from  w  ww  . j  a v a2 s  .  c om*/
    mBuilder.setContentText("");
    mBuilder.setProgress(maxProgress, overallProgress, false);

    mNotifyManager = (NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE);
    mNotification = mBuilder.build();
    mNotification.flags |= Notification.FLAG_INSISTENT | Notification.FLAG_NO_CLEAR;
    mNotifyManager.notify(mNotificationId, mNotification);

}

From source file:com.aniruddhc.acemusic.player.Services.BuildMusicLibraryService.java

@Override
public void onProgressUpdate(AsyncBuildLibraryTask task, String mCurrentTask, int overallProgress,
        int maxProgress, boolean mediaStoreTransferDone) {
    mBuilder = new NotificationCompat.Builder(mContext);
    mBuilder.setSmallIcon(R.drawable.notif_icon);
    mBuilder.setContentTitle(mCurrentTask);
    mBuilder.setTicker(mCurrentTask);//from ww w .  ja v  a 2 s.c o  m
    mBuilder.setContentText("");
    mBuilder.setProgress(maxProgress, overallProgress, false);

    mNotifyManager = (NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE);
    mNotification = mBuilder.build();
    mNotification.flags |= Notification.FLAG_INSISTENT | Notification.FLAG_NO_CLEAR;
    mNotifyManager.notify(mNotificationId, mNotification);

}

From source file:com.f2prateek.dfg.core.GenerateFrameService.java

@Override
public void startingImage(Bitmap screenshot) {
    // Create the large notification icon
    int imageWidth = screenshot.getWidth();
    int imageHeight = screenshot.getHeight();
    int iconSize = resources.getDimensionPixelSize(android.R.dimen.notification_large_icon_height);
    final int shortSide = imageWidth < imageHeight ? imageWidth : imageHeight;

    // Check for if config is null, http://crashes.to/s/dd0857c8648
    Bitmap preview = Bitmap.createBitmap(shortSide, shortSide,
            screenshot.getConfig() == null ? Bitmap.Config.ARGB_8888 : screenshot.getConfig());
    Canvas c = new Canvas(preview);
    Paint paint = new Paint();
    ColorMatrix desat = new ColorMatrix();
    desat.setSaturation(0.25f);//from   w  w  w  . jav a 2s  . c o m
    paint.setColorFilter(new ColorMatrixColorFilter(desat));
    Matrix matrix = new Matrix();
    matrix.postTranslate((shortSide - imageWidth) / 2, (shortSide - imageHeight) / 2);
    c.drawBitmap(screenshot, matrix, paint);
    c.drawColor(0x40FFFFFF);

    Bitmap croppedIcon = Bitmap.createScaledBitmap(preview, iconSize, iconSize, true);

    Intent nullIntent = new Intent(this, MainActivity.class);
    nullIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

    notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    notificationBuilder = new NotificationCompat.Builder(this)
            .setTicker(resources.getString(R.string.screenshot_saving_ticker))
            .setContentTitle(resources.getString(R.string.screenshot_saving_title))
            .setSmallIcon(R.drawable.ic_stat_app_notification)
            .setStyle(new NotificationCompat.BigPictureStyle().bigPicture(preview))
            .setContentIntent(PendingIntent.getActivity(this, 0, nullIntent, 0))
            .setWhen(System.currentTimeMillis()).setProgress(0, 0, true).setLargeIcon(croppedIcon);

    Notification n = notificationBuilder.build();
    n.flags |= Notification.FLAG_NO_CLEAR;
    notificationManager.notify(DFG_NOTIFICATION_ID, n);
}