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:com.example.recordvoice.service.RecordService.java
private void startService() { if (!onForeground) { Log.d(Constants.TAG, "RecordService startService"); Intent intent = new Intent(this, MainActivity.class); // intent.setAction(Intent.ACTION_VIEW); // intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT); PendingIntent pendingIntent = PendingIntent.getActivity(getBaseContext(), 0, intent, 0); Notification notification = new NotificationCompat.Builder(getBaseContext()) .setContentTitle(this.getString(R.string.notification_title)) .setTicker(this.getString(R.string.notification_ticker)) .setContentText(this.getString(R.string.notification_text)).setSmallIcon(R.mipmap.ic_launcher) .setContentIntent(pendingIntent).setOngoing(true).getNotification(); notification.flags = Notification.FLAG_NO_CLEAR; startForeground(1337, notification); onForeground = true;/*from ww w . j a va 2 s. c o m*/ } }
From source file:org.unchiujar.umbra2.services.LocationService.java
private Notification createNotification() { String contentTitle = getString(R.string.app_name); String running = getString(R.string.running); CharSequence tickerText = contentTitle + " " + running; // instantiate notification Notification notification = new NotificationCompat.Builder(this).setTicker(tickerText) .setWhen(System.currentTimeMillis()).setSmallIcon(R.drawable.icon).build(); notification.flags |= Notification.FLAG_NO_CLEAR; notification.flags |= Notification.FLAG_ONGOING_EVENT; // Define the Notification's expanded message and Intent: CharSequence contentText = contentTitle + " " + running; Intent notificationIntent = new Intent(this, FogOfExplore.class); // notificationIntent.setAction("android.intent.action.VIEW"); PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT); notification.setLatestEventInfo(this, contentTitle, contentText, contentIntent); return notification; }
From source file:com.android.madpausa.cardnotificationviewer.ConcreteNotificationListenerService.java
/** * sends the service notification/*from w ww . ja v a 2s .com*/ */ private void handleServiceNotification() { NotificationManager nManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); //filtering archived notification list List<StatusBarNotification> filteredArchivedNotificationList = baseNotificationFilter .applyFilter(archivedNotificationMap.values(), notificationGroups, true); int filteredArchiveddSize = filteredArchivedNotificationList.size(); //should show notification only if there are notifications to be shown if (filteredArchiveddSize > 0) { NotificationCompat.Builder nBuilder = new NotificationCompat.Builder(this); nBuilder.setContentTitle( String.format(getString(R.string.service_notification_text), filteredArchiveddSize)); nBuilder.setSmallIcon(R.drawable.ic_notification); //gets the correct color resource, based on android version if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) nBuilder.setColor(getResources().getColor(R.color.app_background, null)); else //noinspection deprecation nBuilder.setColor(getResources().getColor(R.color.app_background)); //setting the intent Intent resultIntent = new Intent(this, MainActivity.class); //setting the extra containing the archived notifications resultIntent.putExtra(ARCHIVED_NOTIFICATIONS_EXTRA, new HashSet<>(archivedNotificationMap.keySet())); TaskStackBuilder stackBuilder = TaskStackBuilder.create(this); stackBuilder.addParentStack(MainActivity.class); stackBuilder.addNextIntent(resultIntent); PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); nBuilder.setContentIntent(resultPendingIntent); //low priority, not min, as it has to show in the lockscreen nBuilder.setPriority(Notification.PRIORITY_LOW); Notification notification = nBuilder.build(); //this notification should be sticky notification.flags |= Notification.FLAG_NO_CLEAR; nManager.notify(SERVICE_NOTIFICATION, 0, notification); } //else I should remove the notification else nManager.cancel(SERVICE_NOTIFICATION, 0); }
From source file:dk.microting.softkeyboard.autoupdateapk.AutoUpdateApk.java
private void raise_notification() { String ns = Context.NOTIFICATION_SERVICE; NotificationManager nm = (NotificationManager) context.getSystemService(ns); String update_file = preferences.getString(UPDATE_FILE, ""); if (update_file.length() > 0) { // raise notification Notification notification = new Notification(appIcon, appName + " update", System.currentTimeMillis()); notification.flags |= Notification.FLAG_AUTO_CANCEL | Notification.FLAG_NO_CLEAR; CharSequence contentTitle = appName + " update available"; CharSequence contentText = "Select to install"; Intent notificationIntent = new Intent(Intent.ACTION_VIEW); notificationIntent.setDataAndType( Uri.parse("file://" + context.getFilesDir().getAbsolutePath() + "/" + update_file), ANDROID_PACKAGE);//from w ww . j a va2 s. com PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, 0); notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent); nm.notify(NOTIFICATION_ID, notification); } else { nm.cancel(NOTIFICATION_ID); } }
From source file:org.hansel.myAlert.LocationManagement.java
private void showNotification() { Intent i = new Intent(this, MainActivity.class); i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); i.addCategory(Intent.CATEGORY_LAUNCHER); PendingIntent pi = PendingIntent.getActivity(this, 0, i, 0); NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.ic_launcher).setContentTitle(getResources().getString(R.string.app_name)) .setContentText("Hansel Running").setContentIntent(pi); Notification notif = mBuilder.build(); notif.flags = Notification.FLAG_NO_CLEAR; startForeground(1337, notif);//from w w w. j av a 2s . c o m }
From source file:uk.ac.ucl.excites.sapelli.relay.BackgroundService.java
@SuppressWarnings("deprecation") public void setServiceForeground(Context mContext) { final int myID = 9999; // The intent to launch when the user clicks the expanded notification Intent mIntent = new Intent(mContext, BackgroundActivity.class); mIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); PendingIntent pendIntent = PendingIntent.getActivity(mContext, 0, mIntent, 0); // This constructor is deprecated. Use Notification.Builder instead Notification mNotification = new Notification(R.drawable.ic_launcher, getString(R.string.app_name), System.currentTimeMillis()); // This method is deprecated. Use Notification.Builder instead. mNotification.setLatestEventInfo(this, getString(R.string.app_name), getString(R.string.notification), pendIntent);/* ww w. ja v a 2 s.c om*/ mNotification.flags |= Notification.FLAG_NO_CLEAR; startForeground(myID, mNotification); }
From source file:com.csipsimple.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 ww . ja v a2s .c o m 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.build(); notification.flags |= Notification.FLAG_NO_CLEAR; notificationManager.notify(CALL_NOTIF_ID, notification); }
From source file:fr.ardeconnect.proxy.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("ARDECO PROXY").setContentText("idle").setSmallIcon(R.drawable.ardeco_off) .setAutoCancel(false).build(); } else {//from ww w. j ava 2 s . co m mNotification = new Notification.Builder(this) .setContentTitle("ARDECO PROXY").setContentText("active").setSmallIcon(R.drawable.ardeco_on) .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:edu.sage.spark.service.XmppConnectionAdapter.java
/** * Update the notification for the Beem status. * @param status the status to display./*from w w w. j a v a2 s . c o m*/ * @param text the text to display. */ @SuppressWarnings("deprecation") private void updateNotification(int status, String text) { String mNotificationText = "Spark Status"; //almyz125 added this Notification mStatusNotification; mStatusNotification = new Notification(Status.getIconBarFromStatus(status), text, System.currentTimeMillis()); mStatusNotification.defaults = Notification.DEFAULT_LIGHTS; mStatusNotification.flags = Notification.FLAG_NO_CLEAR | Notification.FLAG_ONGOING_EVENT; mStatusNotification.setLatestEventInfo(mService, mNotificationText, text, //almyz125 added mNotificationText variable PendingIntent.getActivity(mService, 0, new Intent(mService, ChangeStatus.class), 0)); // bypass the preferences for notification mService.getNotificationManager().notify(BeemService.NOTIFICATION_STATUS_ID, mStatusNotification); }
From source file:com.beem.project.beem.service.XmppConnectionAdapter.java
/** * Update the notification for the Beem status. * @param status the status to display.// w w w . ja v a 2s. co m * @param text the text to display. */ private void updateNotification(int status, String text) { Notification mStatusNotification; mStatusNotification = new Notification(Status.getIconBarFromStatus(status), text, System.currentTimeMillis()); mStatusNotification.defaults = Notification.DEFAULT_LIGHTS; mStatusNotification.flags = Notification.FLAG_NO_CLEAR | Notification.FLAG_ONGOING_EVENT; mStatusNotification.setLatestEventInfo(mService, "Beem Status", text, PendingIntent.getActivity(mService, 0, new Intent(mService, ChangeStatus.class), 0)); // bypass the preferences for notification mService.getNotificationManager().notify(BeemService.NOTIFICATION_STATUS_ID, mStatusNotification); }