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.innoc.secureline.ui.NotificationBarManager.java

public static void setCallInProgress(Context context) {
    NotificationManager notificationManager = (NotificationManager) context
            .getSystemService(Context.NOTIFICATION_SERVICE);

    Intent contentIntent = new Intent(context, SecureLine.class);
    contentIntent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
    PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, contentIntent, 0);
    String notificationText = context.getString(R.string.NotificationBarManager_redphone_call_in_progress);
    Notification notification = new Notification(R.drawable.stat_sys_phone_call, null,
            System.currentTimeMillis());

    notification.setLatestEventInfo(context, notificationText, notificationText, pendingIntent);
    notification.flags = Notification.FLAG_NO_CLEAR;
    notificationManager.notify(RED_PHONE_NOTIFICATION, notification);
}

From source file:com.mindprotectionkit.freephone.ui.NotificationBarManager.java

public static void setCallInProgress(Context context) {
    NotificationManager notificationManager = (NotificationManager) context
            .getSystemService(Context.NOTIFICATION_SERVICE);

    Intent contentIntent = new Intent(context, RedPhone.class);
    contentIntent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
    PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, contentIntent, 0);
    String notificationText = context.getString(R.string.NotificationBarManager_redphone_call_in_progress);
    Notification notification = new Notification(R.drawable.stat_sys_phone_call, null,
            System.currentTimeMillis());

    notification.setLatestEventInfo(context, notificationText, notificationText, pendingIntent);
    notification.flags = Notification.FLAG_NO_CLEAR;
    notificationManager.notify(RED_PHONE_NOTIFICATION, notification);
}

From source file:fr.simon.marquis.secretcodes.ui.CrawlerNotification.java

private static void notify(final Context context, final Notification notification) {
    notification.flags |= Notification.FLAG_NO_CLEAR;
    final NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ECLAIR) {
        nm.notify(NOTIFICATION_TAG, 0, notification);
    } else {//from  ww w .jav a2 s .c  o m
        nm.notify(NOTIFICATION_TAG.hashCode(), notification);
    }
}

From source file:org.ametro.util.WebUtil.java

public static void downloadFileAsync(final Context appContext, final File path, final URI uri,
        final File temp) {

    final DownloadContext context = new DownloadContext();
    context.Path = path;//from  w  w w  .  ja  v a2  s .c o  m
    context.IsCanceled = false;
    context.IsUnpackFinished = false;
    context.IsFailed = false;

    final NotificationManager notificationManager = (NotificationManager) appContext
            .getSystemService(Context.NOTIFICATION_SERVICE);

    final Handler handler = new Handler();

    final Runnable updateProgress = new Runnable() {
        public void run() {
            if (context.Notification == null) {
                context.Notification = new Notification(android.R.drawable.stat_sys_download,
                        "Downloading icons", System.currentTimeMillis());
                context.Notification.flags = Notification.FLAG_NO_CLEAR;
                Intent notificationIntent = new Intent();
                context.ContentIntent = PendingIntent.getActivity(appContext, 0, notificationIntent, 0);
            }
            if (context.IsFailed) {
                notificationManager.cancelAll();
                context.Notification = new Notification(android.R.drawable.stat_sys_warning,
                        "Icons download failed", System.currentTimeMillis());
                context.Notification.setLatestEventInfo(appContext, "aMetro", "Icons downloaded failed",
                        context.ContentIntent);
                notificationManager.notify(2, context.Notification);

            } else if (context.IsUnpackFinished) {
                notificationManager.cancelAll();
                context.Notification = new Notification(android.R.drawable.stat_sys_download_done,
                        "Icons unpacked", System.currentTimeMillis());
                context.Notification.setLatestEventInfo(appContext, "aMetro", "Icons downloaded and unpacked.",
                        context.ContentIntent);
                notificationManager.notify(3, context.Notification);

            } else if (context.Position == 0 && context.Total == 0) {
                context.Notification.setLatestEventInfo(appContext, "aMetro",
                        "Download icons: connecting server", context.ContentIntent);
                notificationManager.notify(1, context.Notification);
            } else if (context.Position < context.Total) {
                context.Notification.setLatestEventInfo(appContext, "aMetro",
                        "Download icons: " + context.Position + "/" + context.Total, context.ContentIntent);
                notificationManager.notify(1, context.Notification);
            } else {
                context.Notification.setLatestEventInfo(appContext, "aMetro", "Icons unpacking",
                        context.ContentIntent);
                notificationManager.notify(1, context.Notification);
            }
        }
    };

    final Thread async = new Thread() {
        public void run() {
            WebUtil.downloadFile(context, uri, temp, false, new IDownloadListener() {

                public void onBegin(Object context, File file) {
                    DownloadContext downloadContext = (DownloadContext) context;
                    downloadContext.Total = 0;
                    downloadContext.Position = 0;
                    handler.removeCallbacks(updateProgress);
                    handler.post(updateProgress);
                }

                public boolean onUpdate(Object context, long position, long total) {
                    DownloadContext downloadContext = (DownloadContext) context;
                    downloadContext.Total = total;
                    downloadContext.Position = position;
                    handler.removeCallbacks(updateProgress);
                    handler.post(updateProgress);
                    return !downloadContext.IsCanceled;
                }

                public void onDone(Object context, File file) throws Exception {
                    DownloadContext downloadContext = (DownloadContext) context;
                    File path = downloadContext.Path;
                    ZipUtil.unzip(file, path);
                    downloadContext.IsUnpackFinished = true;
                    handler.removeCallbacks(updateProgress);
                    handler.post(updateProgress);
                }

                public void onCanceled(Object context, File file) {
                    DownloadContext downloadContext = (DownloadContext) context;
                    downloadContext.IsCanceled = true;
                    handler.removeCallbacks(updateProgress);
                    handler.post(updateProgress);
                }

                public void onFailed(Object context, File file, Throwable reason) {
                    DownloadContext downloadContext = (DownloadContext) context;
                    downloadContext.IsFailed = true;
                    handler.removeCallbacks(updateProgress);
                    handler.post(updateProgress);
                }

            });
        };
    };
    async.start();
}

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

public static void showPlayingNotification(final Context context, final DownloadService downloadService,
        final Handler handler, MusicDirectory.Entry song) {
    // Set the icon, scrolling text and timestamp
    final Notification notification = new Notification(R.drawable.stat_notify_playing, song.getTitle(),
            System.currentTimeMillis());

    final boolean playing = downloadService.getPlayerState() == PlayerState.STARTED;
    if (playing) {
        notification.flags |= Notification.FLAG_NO_CLEAR | Notification.FLAG_ONGOING_EVENT;
    }//  www  . j  av  a 2 s  .  co m
    boolean remote = downloadService.isRemoteEnabled();
    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);
        notification.bigContentView = expandedContentView;
        notification.priority = Notification.PRIORITY_HIGH;
    }
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        notification.visibility = Notification.VISIBILITY_PUBLIC;
    }

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

    Intent notificationIntent = new Intent(context, SubsonicFragmentActivity.class);
    notificationIntent.putExtra(Constants.INTENT_EXTRA_NAME_DOWNLOAD, true);
    notificationIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | 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() {
                downloadService.stopForeground(true);
                showDownloadingNotification(context, downloadService, handler,
                        downloadService.getCurrentDownloading(),
                        downloadService.getBackgroundDownloads().size());
                downloadService.startForeground(NOTIFICATION_ID_PLAYING, notification);
            }
        });
    } else {
        handler.post(new Runnable() {
            @Override
            public void run() {
                if (playing) {
                    downloadService.startForeground(NOTIFICATION_ID_PLAYING, notification);
                } else {
                    playShowing = false;
                    persistentPlayingShowing = true;
                    NotificationManager notificationManager = (NotificationManager) context
                            .getSystemService(Context.NOTIFICATION_SERVICE);
                    downloadService.stopForeground(false);
                    notificationManager.notify(NOTIFICATION_ID_PLAYING, notification);
                }
            }
        });
    }

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

From source file:org.telegram.kleegram.autoanswer.AutoAnswerNotifier.java

private void enableNotification() {
    // Intent to call to turn off AutoAnswer
    Intent notificationIntent = new Intent(mContext, AutoAnswerPreferenceActivity.class);
    PendingIntent pendingIntent = PendingIntent.getActivity(mContext, 0, notificationIntent, 0);

    // Create the notification
    Notification notification = new Notification(R.drawable.stat_sys_autoanswer, null, 0);
    notification.flags |= Notification.FLAG_ONGOING_EVENT | Notification.FLAG_NO_CLEAR;
    NotificationCompat.Builder builder = new NotificationCompat.Builder(mContext);
    notification = builder.setContentIntent(pendingIntent).setSmallIcon(R.drawable.stat_sys_autoanswer)
            .setAutoCancel(true).setContentTitle(mContext.getString(R.string.notification_title))
            .setContentText(mContext.getString(R.string.notification_text)).build();
    mNotificationManager.notify(NOTIFICATION_ID, notification);

}

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

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

    //Create a persistent notification that keeps this service running and displays the scan progress.
    mBuilder = new NotificationCompat.Builder(mContext);
    mBuilder.setSmallIcon(R.mipmap.ic_launcher);
    mBuilder.setContentTitle(getResources().getString(R.string.building_music_library));
    mBuilder.setTicker(getResources().getString(R.string.building_music_library));
    mBuilder.setContentText("");
    mBuilder.setProgress(0, 0, true);/*from   w  ww . j  a v  a2 s . c o  m*/

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

    startForeground(mNotificationId, mNotification);

    //Go crazy with a full-on scan.
    AsyncBuildLibraryTask task = new AsyncBuildLibraryTask(mContext, this);
    task.setOnBuildLibraryProgressUpdate(WelcomeActivity.mBuildingLibraryProgressFragment);
    task.setOnBuildLibraryProgressUpdate(this);
    task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);

    return START_STICKY;
}

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

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

    //Create a persistent notification that keeps this service running and displays the scan progress.
    mBuilder = new NotificationCompat.Builder(mContext);
    mBuilder.setSmallIcon(R.drawable.notif_icon);
    mBuilder.setContentTitle(getResources().getString(R.string.building_music_library));
    mBuilder.setTicker(getResources().getString(R.string.building_music_library));
    mBuilder.setContentText("");
    mBuilder.setProgress(0, 0, true);/*from w w  w  .  j  av  a2s . com*/

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

    startForeground(mNotificationId, mNotification);

    //Go crazy with a full-on scan.
    AsyncBuildLibraryTask task = new AsyncBuildLibraryTask(mContext, this);
    task.setOnBuildLibraryProgressUpdate(WelcomeActivity.mBuildingLibraryProgressFragment);
    task.setOnBuildLibraryProgressUpdate(this);
    task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);

    return START_STICKY;
}

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

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

    //Launch a notification to set the service as a foreground service.
    builder = new NotificationCompat.Builder(this);
    builder.setSmallIcon(R.drawable.ic_launcher);
    builder.setContentTitle(getResources().getString(R.string.downloading_missing_cover_art));
    builder.setTicker(getResources().getString(R.string.downloading_missing_cover_art));
    builder.setContentText(null);/*w w  w  .j av a2 s .c o m*/

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

    startForeground(NOTIFICATION_ID, notification);

    //Call the AsyncTask that checks for missing art and downloads them.
    AsyncAutoGetAlbumArtTask task = new AsyncAutoGetAlbumArtTask(mContext,
            SettingsActivity____.mSettingsActivity);
    task.execute();

    return START_STICKY;
}

From source file:dk.dr.radio.afspilning.HoldAppIHukommelsenService.java

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    Log.d("AfspillerService onStartCommand(" + intent + " " + flags + " " + startId);

    String kanalNavn = intent == null ? null : intent.getStringExtra("kanalNavn");
    if (kanalNavn == null)
        kanalNavn = "";

    NotificationCompat.Builder b = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.notifikation_ikon).setContentTitle("DR Radio").setContentText(kanalNavn)
            .setContentIntent(PendingIntent.getActivity(this, 0, new Intent(this, Afspilning_akt.class), 0))
            .setContent(AfspillerWidget.lavRemoteViews());

    //notification = new Notification(R.drawable.notifikation_ikon, null, 0);
    Notification notification = b.build();

    // PendingIntent er til at pege p aktiviteten der skal startes hvis brugeren vlger notifikationen
    //notification.contentIntent = PendingIntent.getActivity(this, 0, new Intent(this, Afspilning_akt.class), 0);
    notification.flags |= (Notification.FLAG_NO_CLEAR | Notification.FLAG_ONGOING_EVENT);

    //notification.setLatestEventInfo(this, "Radio", kanalNavn, notification.contentIntent);
    startForeground(NOTIFIKATION_ID, notification);
    return START_STICKY;
}