List of usage examples for android.app Notification FLAG_NO_CLEAR
int FLAG_NO_CLEAR
To view the source code for android.app Notification FLAG_NO_CLEAR.
Click Source Link
From source file:net.tac42.subtails.util.Util.java
public static void showPlayingNotification(final Context context, final DownloadServiceImpl downloadService, Handler handler, MusicDirectory.Entry song) { // Use the same text for the ticker and the expanded notification String title = song.getTitle(); String text = song.getArtist(); // Set the icon, scrolling text and timestamp final Notification notification = new Notification(R.drawable.stat_notify_playing, title, System.currentTimeMillis()); notification.flags |= Notification.FLAG_NO_CLEAR | Notification.FLAG_ONGOING_EVENT; RemoteViews contentView = new RemoteViews(context.getPackageName(), R.layout.notification); // Set the album art. try {/*from ww w. j a va2s . c o m*/ int size = context.getResources().getDrawable(R.drawable.unknown_album).getIntrinsicHeight(); Bitmap bitmap = FileUtil.getAlbumArtBitmap(context, song, size); if (bitmap == null) { // set default album art contentView.setImageViewResource(R.id.notification_image, R.drawable.unknown_album); } else { contentView.setImageViewBitmap(R.id.notification_image, bitmap); } } catch (Exception x) { Log.w(TAG, "Failed to get notification cover art", x); contentView.setImageViewResource(R.id.notification_image, R.drawable.unknown_album); } // 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; Intent notificationIntent = new Intent(context, DownloadActivity.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 SubtailsAppWidgetProvider.getInstance().notifyChange(context, downloadService, true); }
From source file:com.orange.oidc.secproxy_service.Service.java
private void showNotification(boolean bProtect) { Logd(TAG, "show protected icon " + bProtect); // this is it, we'll build the notification! // in the addAction method, if you don't want any icon, just set the first param to 0 Notification mNotification = null; if (bProtect) { mNotification = new Notification.Builder(this) .setContentTitle("SECURE OIDC PROXY").setContentText("privacy protected") .setSmallIcon(R.drawable.masked_on).setAutoCancel(false).build(); } else {// w ww. j ava2 s . c o m mNotification = new Notification.Builder(this) .setContentTitle("SECURE OIDC PROXY").setContentText("privacy not protected") .setSmallIcon(R.drawable.masked_off).setAutoCancel(false).build(); } // to make it non clearable mNotification.flags |= Notification.FLAG_NO_CLEAR; NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); // If you want to hide the notification after it was selected, do the code below // myNotification.flags |= Notification.FLAG_AUTO_CANCEL; notificationManager.notify(0, mNotification); }
From source file:com.bonsai.btcreceive.WalletService.java
private void showStatusNotification() { // In this sample, we'll use the same text for the ticker and // the expanded notification CharSequence started_txt = getText(R.string.wallet_service_started); CharSequence info_txt = getText(R.string.wallet_service_info); Notification note = new Notification(R.drawable.ic_stat_notify, started_txt, System.currentTimeMillis()); Intent intent = new Intent(this, MainActivity.class); intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); PendingIntent contentIntent = PendingIntent.getActivity(this, 0, intent, 0); // Set the info for the views that show in the notification panel. note.setLatestEventInfo(this, getText(R.string.wallet_service_label), info_txt, contentIntent); note.flags |= Notification.FLAG_NO_CLEAR; startForeground(NOTIFICATION, note); }
From source file:com.halseyburgund.rwframework.core.RWService.java
@Override public int onStartCommand(Intent intent, int flags, int startId) { // intent will be null on restart! if (intent != null) { getSettingsFromIntent(intent);//from w ww . j av a 2 s .c o m } // create a pending intent to start the specified activity from the notification Intent ovIntent = new Intent(this, mNotificationActivity); mNotificationPendingIntent = PendingIntent.getActivity(this, 0, ovIntent, Intent.FLAG_ACTIVITY_NEW_TASK); // create a notification and move service to foreground mRwNotification = new Notification(mNotificationIconId, "Roundware Service Started", System.currentTimeMillis()); mRwNotification.number = 1; mRwNotification.flags = mRwNotification.flags | Notification.FLAG_FOREGROUND_SERVICE | Notification.FLAG_ONGOING_EVENT | Notification.FLAG_NO_CLEAR; setNotificationText(""); startForeground(NOTIFICATION_ID, mRwNotification); // try to go on-line, this will attempt to get the configuration and tags manageSessionState(SessionState.ON_LINE); return Service.START_STICKY; }
From source file:net.ben.subsonic.androidapp.util.Util.java
public static void showPlayingNotification(final Context context, Handler handler, MusicDirectory.Entry song) { // Use the same text for the ticker and the expanded notification String title = song.getTitle(); // Set the icon, scrolling text and timestamp final Notification notification = new Notification(R.drawable.stat_notify_playing, title, System.currentTimeMillis()); notification.flags |= Notification.FLAG_NO_CLEAR | Notification.FLAG_ONGOING_EVENT; // The PendingIntent to launch our activity if the user selects this notification PendingIntent contentIntent = PendingIntent.getActivity(context, 0, new Intent(context, FragActivity.class), 0);//from www . j a v a 2 s .c om String text = song.getArtist(); notification.setLatestEventInfo(context, title, text, contentIntent); // Send the notification. handler.post(new Runnable() { @Override public void run() { NotificationManager notificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.notify(Constants.NOTIFICATION_ID_PLAYING, notification); } }); // Update widget DownloadService service = DownloadServiceImpl.getInstance(); if (service != null) { SubsonicAppWidgetProvider.getInstance().notifyChange(context, service, true); } }
From source file:com.orangelabs.rcs.ri.ConnectionManager.java
private void addImsConnectionNotification(boolean connected, RcsServiceRegistration.ReasonCode reason) { /* Create notification */ Intent intent = new Intent(mContext, SettingsDisplay.class); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); PendingIntent contentIntent = PendingIntent.getActivity(mContext, 0, intent, 0); int iconId;// w w w. j a v a 2s. c o m String label; if (connected) { iconId = R.drawable.ri_notif_on_icon; label = mContext.getString(R.string.ims_connected); } else { iconId = R.drawable.ri_notif_off_icon; if (RcsServiceRegistration.ReasonCode.BATTERY_LOW == reason) { label = mContext.getString(R.string.ims_battery_disconnected); } else { label = mContext.getString(R.string.ims_disconnected); } } String title = mContext.getString(R.string.notification_title_rcs_service); /* Create notification */ Notification notif = buildImsConnectionNotification(contentIntent, title, label, iconId); notif.flags = Notification.FLAG_NO_CLEAR | Notification.FLAG_FOREGROUND_SERVICE; /* Send notification */ NotificationManager notificationManager = (NotificationManager) mContext .getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.notify(SERVICE_NOTIFICATION, notif); }
From source file:github.daneren2005.dsub.util.Util.java
public static void showPlayingNotification(final Context context, final DownloadServiceImpl downloadService, 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()); notification.flags |= Notification.FLAG_NO_CLEAR | Notification.FLAG_ONGOING_EVENT; boolean playing = downloadService.getPlayerState() == PlayerState.STARTED; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { RemoteViews expandedContentView = new RemoteViews(context.getPackageName(), R.layout.notification_expanded); setupViews(expandedContentView, context, song, playing); notification.bigContentView = expandedContentView; }//from w w w . j ava 2s. c o m RemoteViews smallContentView = new RemoteViews(context.getPackageName(), R.layout.notification); setupViews(smallContentView, context, song, playing); notification.contentView = smallContentView; Intent notificationIntent = new Intent(context, DownloadActivity.class); notification.contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, 0); handler.post(new Runnable() { @Override public void run() { downloadService.startForeground(Constants.NOTIFICATION_ID_PLAYING, notification); } }); // Update widget DSubWidgetProvider.getInstance().notifyChange(context, downloadService, true); }
From source file:org.distantshoresmedia.keyboard.LatinIME.java
private void setNotification(boolean visible) { final String ACTION = "org.distantshoresmedia.translationkeyboard.SHOW"; final int ID = 1; String ns = Context.NOTIFICATION_SERVICE; NotificationManager mNotificationManager = (NotificationManager) getSystemService(ns); if (visible && mNotificationReceiver == null) { int icon = R.drawable.icon; CharSequence text = "Keyboard notification enabled."; long when = System.currentTimeMillis(); // TODO: clean this up? mNotificationReceiver = new NotificationReceiver(this); final IntentFilter pFilter = new IntentFilter(ACTION); registerReceiver(mNotificationReceiver, pFilter); Intent notificationIntent = new Intent(ACTION); PendingIntent contentIntent = PendingIntent.getBroadcast(getApplicationContext(), 1, notificationIntent, 0);/*from ww w .jav a2 s .c o m*/ //PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0); String title = "Show translationKeyboard Keyboard"; String body = "Select this to open the keyboard. Disable in settings."; // Notification notification = new Notification(icon, text, when); // // notification.flags |= Notification.FLAG_ONGOING_EVENT | Notification.FLAG_NO_CLEAR; // notification.setLatestEventInfo(getApplicationContext(), title, body, contentIntent); NotificationCompat.Builder builder = new NotificationCompat.Builder(getApplicationContext()); builder.setContentIntent(contentIntent).setSmallIcon(icon) .setLargeIcon(BitmapFactory.decodeResource(getApplicationContext().getResources(), icon)) .setTicker(body).setWhen(System.currentTimeMillis()).setAutoCancel(true).setContentTitle(title) .setContentText(body); Notification notification = builder.build(); notification.flags |= Notification.FLAG_ONGOING_EVENT | Notification.FLAG_NO_CLEAR; mNotificationManager.notify(ID, notification); } else if (mNotificationReceiver != null) { mNotificationManager.cancel(ID); unregisterReceiver(mNotificationReceiver); mNotificationReceiver = null; } }
From source file:com.bonsai.wallet32.WalletService.java
private void showStatusNotification() { CharSequence started_txt = getText(R.string.wallet_service_started); CharSequence info_txt = getText(R.string.wallet_service_info); Notification note = new Notification(R.drawable.ic_stat_notify, started_txt, System.currentTimeMillis()); Intent intent = new Intent(this, MainActivity.class); intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); PendingIntent contentIntent = PendingIntent.getActivity(this, 0, intent, 0); // Set the info for the views that show in the notification panel. note.setLatestEventInfo(this, getText(R.string.wallet_service_label), info_txt, contentIntent); note.flags |= Notification.FLAG_NO_CLEAR; startForeground(NOTIFICATION, note); }