List of usage examples for android.app Notification FLAG_AUTO_CANCEL
int FLAG_AUTO_CANCEL
To view the source code for android.app Notification FLAG_AUTO_CANCEL.
Click Source Link
From source file:de.dev.eth0.rssreader.app.util.NotificationManagerImpl.java
@Override public void sendFeedUpdateFailedNotification(Request request, IOException ioe) { //TODO: add more information into the notification //TODO: don't display this notification multiple times, that's annoyin if (isNotificationDisabled()) { return;/*from ww w . j a v a2s . c om*/ } android.app.NotificationManager notificationManager = (android.app.NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); NotificationCompat.Builder builder = new NotificationCompat.Builder(context) .setSmallIcon(R.drawable.icon_empty_18dp) .setContentTitle(context.getString(R.string.notification_update_failed_title)) .setContentText(ioe.getMessage()).setAutoCancel(true); Notification notification = builder.build(); notification.flags = Notification.FLAG_AUTO_CANCEL; notificationManager.notify(ID_UPDATE_FAILED, notification); }
From source file:com.asb.spandan2014.GcmIntentService.java
private void sendNotification(String msg) { mNotificationManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE); Intent resultIntent = new Intent(this, AlertsActivity.class); TaskStackBuilder stackBuilder = TaskStackBuilder.create(this); // Adds the back stack stackBuilder.addParentStack(AlertsActivity.class); // Adds the Intent to the top of the stack stackBuilder.addNextIntent(resultIntent); // Gets a PendingIntent containing the entire back stack PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this).setSmallIcon(R.drawable.alerts) .setContentTitle(getString(R.string.spandan_update)) .setDefaults(Notification.DEFAULT_VIBRATE | Notification.FLAG_SHOW_LIGHTS | Notification.FLAG_AUTO_CANCEL | Notification.DEFAULT_LIGHTS) .setStyle(new NotificationCompat.BigTextStyle().bigText(msg)).setContentText(msg); mBuilder.setContentIntent(resultPendingIntent); mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build()); }
From source file:com.waz.zclient.controllers.notifications.NotificationsController.java
@Override @DebugLog//from w w w . j a v a2 s . c o m public void updateGcmNotification(GcmNotificationsList gcmNotificationsList) { Collection<GcmNotification> gcmNotifications = gcmNotificationsList.getNotifications(); if (gcmNotifications == null || gcmNotifications.size() < 1) { notificationManager.cancel(ZETA_MESSAGE_NOTIFICATION_ID); return; } final Notification notification; if (gcmNotifications.size() == 1) { notification = getSingleMesssageNotification(gcmNotifications); } else { // TODO: Would be nice to show the {@link #getSingleMesssageNotification} as a HeadsUpNotification notification = getMultipleMessagesNotification(gcmNotifications); } if (notification == null) { return; } notification.priority = Notification.PRIORITY_HIGH; notification.flags |= Notification.FLAG_AUTO_CANCEL; notification.deleteIntent = gcmNotificationsList.getClearNotificationsIntent(); attachNotificationLed(notification); attachNotificationSound(gcmNotifications, notification); notificationManager.notify(ZETA_MESSAGE_NOTIFICATION_ID, notification); }
From source file:fr.RivaMedia.AnnoncesAutoGenerique.alertes.GcmIntentService.java
private void sendNotification(String titre, String message) { mNotificationManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE); //TODO: remplir //Intent de lancement PackageManager pm = getPackageManager(); Intent lancement = pm.getLaunchIntentForPackage(getPackageName()); PendingIntent contentIntent = PendingIntent.getActivity(this, 0, lancement, 0); NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this).setSmallIcon(R.drawable.app_icon) .setContentTitle(titre).setContentText(message); mBuilder.setContentIntent(contentIntent); Notification notif = mBuilder.build(); notif.flags |= Notification.FLAG_AUTO_CANCEL; mNotificationManager.notify(NOTIFICATION_ID, notif); }
From source file:com.rocketsingh.biker.GCMIntentService.java
/** * Issues a notification to inform the user that server has sent a message. *//*from w w w . ja v a 2s .c om*/ public static void generateNotification(Context context, String message) { int icon = R.drawable.ic_launcher; long when = System.currentTimeMillis(); NotificationManager notificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); Notification notification = new Notification(icon, message, when); String title = context.getString(R.string.app_name); Intent notificationIntent = new Intent(context, MapActivity.class); notificationIntent.putExtra("fromNotification", "notification"); // set intent so it does not start a new activity notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); PendingIntent intent = PendingIntent.getActivity(context, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT); notification.setLatestEventInfo(context, title, message, intent); notification.flags |= Notification.FLAG_AUTO_CANCEL; System.out.println("notification====>" + message); notification.defaults |= Notification.DEFAULT_SOUND; notification.defaults |= Notification.DEFAULT_VIBRATE; // notification.defaults |= Notification.DEFAULT_LIGHTS; notification.flags |= Notification.FLAG_SHOW_LIGHTS; notification.ledARGB = 0x00000000; notification.ledOnMS = 0; notification.ledOffMS = 0; notificationManager.notify(AndyConstants.NOTIFICATION_ID, notification); PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE); PowerManager.WakeLock wakeLock = pm.newWakeLock( PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP | PowerManager.ON_AFTER_RELEASE, "WakeLock"); wakeLock.acquire(); wakeLock.release(); }
From source file:org.andicar.service.UpdateCheckService.java
@Override public void onStart(Intent intent, int startId) { super.onStart(intent, startId); if (getSharedPreferences(StaticValues.GLOBAL_PREFERENCE_NAME, Context.MODE_MULTI_PROCESS) .getBoolean("SendCrashReport", true)) Thread.setDefaultUncaughtExceptionHandler( new AndiCarExceptionHandler(Thread.getDefaultUncaughtExceptionHandler(), this)); try {//w w w . j a v a 2 s .c o m Bundle extras = intent.getExtras(); if (extras == null || extras.getBoolean("setJustNextRun") || !extras.getBoolean("AutoUpdateCheck")) { setNextRun(); stopSelf(); } URL updateURL = new URL(StaticValues.VERSION_FILE_URL); URLConnection conn = updateURL.openConnection(); if (conn == null) return; InputStream is = conn.getInputStream(); if (is == null) return; BufferedInputStream bis = new BufferedInputStream(is); ByteArrayBuffer baf = new ByteArrayBuffer(50); int current = 0; while ((current = bis.read()) != -1) { baf.append((byte) current); } /* Convert the Bytes read to a String. */ String s = new String(baf.toByteArray()); /* Get current Version Number */ int curVersion = getPackageManager().getPackageInfo("org.andicar.activity", 0).versionCode; int newVersion = Integer.valueOf(s); /* Is a higher version than the current already out? */ if (newVersion > curVersion) { //get the whats new message updateURL = new URL(StaticValues.WHATS_NEW_FILE_URL); conn = updateURL.openConnection(); if (conn == null) return; is = conn.getInputStream(); if (is == null) return; bis = new BufferedInputStream(is); baf = new ByteArrayBuffer(50); current = 0; while ((current = bis.read()) != -1) { baf.append((byte) current); } /* Convert the Bytes read to a String. */ s = new String(baf.toByteArray()); mNM = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); notification = null; Intent i = new Intent(this, WhatsNewDialog.class); i.putExtra("UpdateMsg", s); PendingIntent contentIntent = PendingIntent.getActivity(UpdateCheckService.this, 0, i, 0); CharSequence title = getText(R.string.Notif_UpdateTitle); String message = getString(R.string.Notif_UpdateMsg); notification = new Notification(R.drawable.icon_sys_info, message, System.currentTimeMillis()); notification.flags |= Notification.DEFAULT_LIGHTS; notification.flags |= Notification.DEFAULT_SOUND; notification.flags |= Notification.FLAG_AUTO_CANCEL; notification.setLatestEventInfo(UpdateCheckService.this, title, message, contentIntent); mNM.notify(StaticValues.NOTIF_UPDATECHECK_ID, notification); setNextRun(); } stopSelf(); } catch (Exception e) { Log.i("UpdateService", "Service failed."); e.printStackTrace(); } }
From source file:com.scoreflex.ScoreflexGcmClient.java
protected static Notification buildNotification(String text, Context context, int iconResource, PendingIntent pendingIntent) {/*w w w .j av a 2 s.com*/ final PackageManager pm = context.getApplicationContext().getPackageManager(); ApplicationInfo ai; try { ai = pm.getApplicationInfo(context.getPackageName(), 0); } catch (final NameNotFoundException e) { ai = null; } final String applicationName = (String) (ai != null ? pm.getApplicationLabel(ai) : "(unknown)"); NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context) .setContentTitle(applicationName).setContentText(text).setSmallIcon(iconResource); mBuilder.setContentIntent(pendingIntent); Notification notification = mBuilder.build(); notification.defaults = Notification.DEFAULT_SOUND | Notification.DEFAULT_VIBRATE; notification.flags = Notification.FLAG_AUTO_CANCEL; return notification; }
From source file:com.rafamaya.imagesearch.DataLayerListenerService.java
@Override public void onMessageReceived(MessageEvent messageEvent) { LOGD(TAG, "onMessageReceived: " + messageEvent); // Check to see if the message is to start an activity if (messageEvent.getPath().equals(START_ACTIVITY_PATH)) { Intent startIntent = new Intent(this, PhotoActivity.class).setAction(Intent.ACTION_MAIN) .setData(Uri.fromParts("NODEID", messageEvent.getSourceNodeId(), "")); PendingIntent startPendingIntent = PendingIntent.getActivity(this, 0, startIntent, 0); long[] pattern = { 0, 100, 1000 }; Notification notify = new NotificationCompat.Builder(this).setAutoCancel(false) .setStyle(new NotificationCompat.BigTextStyle() .bigText("View or Search images and sync navigation!")) .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher)) .setVibrate(pattern)//ww w . j a va 2s. c om //.addAction(android.R.drawable.ic_menu_gallery, "View", startPendingIntent) .setSmallIcon(R.drawable.ic_launcher).setContentIntent(startPendingIntent).build(); notify.flags |= Notification.FLAG_AUTO_CANCEL; NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this); notificationManager.notify(0, notify); } }
From source file:pj.rozkladWKD.C2DMReceiver.java
public void showNotification(String ticker, String contentTitle, String contentText, PendingIntent intent, int number) { String ns = Context.NOTIFICATION_SERVICE; NotificationManager mNotificationManager = (NotificationManager) getSystemService(ns); int icon = R.drawable.ic_launcher_wkd; CharSequence tickerText = ticker; long when = System.currentTimeMillis(); Notification notification = new Notification(icon, tickerText, when); Context context = getApplicationContext(); notification.number = Prefs.getNotificationMessageNextNumber(context); notification.flags |= Notification.FLAG_AUTO_CANCEL; SharedPreferences prefs = Prefs.get(context); if (prefs.getBoolean(Prefs.NOTIFICATION_SOUND, true)) notification.defaults |= Notification.DEFAULT_SOUND; if (prefs.getBoolean(Prefs.NOTIFICATION_VIBRATION, true)) notification.defaults |= Notification.DEFAULT_VIBRATE; notification.defaults |= Notification.DEFAULT_LIGHTS; notification.setLatestEventInfo(context, contentTitle, contentText, intent); mNotificationManager.notify(NOTIFICATION_ID, notification); }
From source file:com.google.android.gcm.demo.app.GCMIntentService.java
/** * Issues a notification to inform the user that server has sent a message. *//*from ww w . j av a 2 s . c om*/ private static void generateNotification(Context context, String message, String data) { int icon = R.drawable.ic_stat_gcm; long when = System.currentTimeMillis(); NotificationManager notificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.cancel(0); Notification notification = new Notification(icon, message, when); String title = context.getString(R.string.app_name); Intent notificationIntent = new Intent(context, DemoActivity.class); notificationIntent.putExtra(CommonUtilities.EXTRA_TEAM_IN_JSON, data); // set intent so it does not start a new activity notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); PendingIntent intent = PendingIntent.getActivity(context, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT); notification.setLatestEventInfo(context, title, message, intent); notification.flags = Notification.FLAG_AUTO_CANCEL; notificationManager.notify(0, notification); }