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:com.stoneapp.ourvlemoodle2.tasks.DiscussionSync.java
public void addNotification(MoodleDiscussion discussion) { NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context) .setSmallIcon(R.drawable.ourvle_iconsmall).setContentTitle("New Topic") .setContentText(Html.fromHtml(discussion.getName()).toString().trim()); //creates an explicit intent for an activity in your app Intent resultIntent = new Intent(context, PostActivity.class); resultIntent.putExtra("discussionid", discussion.getDiscussionid() + ""); resultIntent.putExtra("discussionname", discussion.getName()); // The stack builder object will contain an artificial back stack for the // started Activity. // This ensures that navigating backward from the Activity leads out of // your application to the Home screen. TaskStackBuilder stackBuilder = TaskStackBuilder.create(context); stackBuilder.addParentStack(PostActivity.class); stackBuilder.addNextIntent(resultIntent); PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); mBuilder.setContentIntent(resultPendingIntent); Notification notification = mBuilder.build(); notification.flags = Notification.DEFAULT_LIGHTS | Notification.FLAG_AUTO_CANCEL; notification.defaults |= Notification.DEFAULT_SOUND; //notification.defaults |= Notification.DEFAULT_VIBRATE; NotificationManager mNotificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); mNotificationManager.notify(discussion.getDiscussionid(), notification); }
From source file:vn.easycare.GCMIntentService.java
/** * Issues a notification to inform the user that server has sent a message. *//*from ww w .j a v a2 s .c om*/ private void generateNotification(Context context, String message) { int icon = R.drawable.ic_launcher; long when = 0;//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, NotificationReceivingActivity.class); // set intent so it does not start a new activity // notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); notificationIntent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP); PendingIntent intent = PendingIntent.getActivity(context, (int) when, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT); notification.setLatestEventInfo(context, title, message, intent); notification.defaults |= Notification.DEFAULT_SOUND; notification.defaults |= Notification.DEFAULT_VIBRATE; notification.flags |= Notification.DEFAULT_LIGHTS | Notification.FLAG_AUTO_CANCEL; notificationManager.notify((int) when, notification); }
From source file:com.snot.whereareyou.GcmIntentService.java
private void sendNotification(String title, Uri uri) { Intent i = new Intent(Intent.ACTION_VIEW, uri); PendingIntent pIntent = PendingIntent.getActivity(this, 0, i, 0); // Build notification Notification notification = new NotificationCompat.Builder(this).setContentTitle(title).setContentText("") .setSmallIcon(R.drawable.ic_launcher).setContentIntent(pIntent).build(); notification.defaults |= Notification.DEFAULT_ALL; // Hide the notification after its selected notification.flags |= Notification.FLAG_AUTO_CANCEL; // Add notification to NotificationManager NotificationManager notificationManager = (NotificationManager) this .getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.notify(NOTIFICATION_ID, notification); }
From source file:com.fanfou.app.opensource.service.DownloadService.java
public static void notifyUpdate(final AppVersionInfo info, final Context context) { final String versionInfo = info.versionName; final NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); final Notification notification = new Notification(R.drawable.ic_notify_icon, "?" + versionInfo, System.currentTimeMillis()); final PendingIntent contentIntent = PendingIntent.getActivity(context, 0, DownloadService.getNewVersionIntent(context, info), 0); notification.setLatestEventInfo(context, "?" + versionInfo, "", contentIntent); notification.flags |= Notification.FLAG_AUTO_CANCEL; nm.notify(2, notification);/* ww w .j a va 2 s .com*/ }
From source file:com.quarterfull.newsAndroid.services.DownloadImagesService.java
private Notification GetNotificationLimitImagesReached(int limit) { Intent intentNewsReader = new Intent(this, NewsReaderListActivity.class); PendingIntent pIntent = PendingIntent.getActivity(this, 0, intentNewsReader, 0); NotificationCompat.Builder notifyBuilder = new NotificationCompat.Builder(this) .setContentTitle("ownCloud News Reader") .setContentText("Only " + limit + " images can be cached at once") .setSmallIcon(R.drawable.ic_notification).setContentIntent(pIntent); Notification notify = notifyBuilder.build(); //Hide the notification after its selected notify.flags |= Notification.FLAG_AUTO_CANCEL; return notify; }
From source file:com.carpool.dj.carpool.model.GcmIntentService.java
/** * Issues a notification to inform the user that server has sent a message. *///from www . j av a 2s . co m @SuppressWarnings("deprecation") private static void generateNotification(Context context, String message, Bundle data, String type) { int icon = R.drawable.ic_launcher; long when = System.currentTimeMillis(); Uri alarmSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); NotificationManager notificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); // Notification notification = new Notification(icon, message, when); Notification notification = new Notification.Builder(context) .setContentTitle(Utils.nowActivity.getString(R.string.app_name)).setContentText(message) .setSmallIcon(icon).setWhen(when).setSound(alarmSound).build(); // String title = context.getString(R.string.app_name); Intent notificationIntent = null; if ("CarEvent".equals(type)) { notificationIntent = new Intent(context, ContentActivity.class); } else { return; } notificationIntent.putExtras(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, Utils.nowActivity.getString(R.string.app_name), message, intent); notification.flags |= Notification.FLAG_AUTO_CANCEL; notificationManager.notify(0, notification); }
From source file:com.automated.taxinow.GCMIntentService.java
/** * Issues a notification to inform the user that server has sent a message. *//*from w ww. ja va2 s.co m*/ private void generateNotification(Context context, String message) { // System.out.println("this is message " + message); // System.out.println("NOTIFICATION RECEIVED!!!!!!!!!!!!!!" + 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, MainDrawerActivity.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(0, 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:com.oliversride.wordryo.Utils.java
public static void postNotification(Context context, Intent intent, String title, String body, int id) { /* nextRandomInt: per this link http://stackoverflow.com/questions/10561419/scheduling-more-than-one-pendingintent-to-same-activity-using-alarmmanager one way to avoid getting the same PendingIntent for similar Intents is to send a different second param each time, though the docs say that param's ignored. *//*w w w . j a v a 2s . c o m*/ PendingIntent pi = null == intent ? null : PendingIntent.getActivity(context, Utils.nextRandomInt(), intent, PendingIntent.FLAG_ONE_SHOT); int defaults = Notification.FLAG_AUTO_CANCEL; if (CommonPrefs.getSoundNotify(context)) { defaults |= Notification.DEFAULT_SOUND; } if (CommonPrefs.getVibrateNotify(context)) { defaults |= Notification.DEFAULT_VIBRATE; } Notification notification = new NotificationCompat.Builder(context).setContentIntent(pi) .setSmallIcon(R.drawable.notify) //.setTicker(body) //.setWhen(time) .setAutoCancel(true).setDefaults(defaults).setContentTitle(title).setContentText(body).build(); NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); nm.notify(id, notification); }
From source file:com.cbtec.eliademy.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*/ private static void generateNotification(Context context, String message) { int icon = R.drawable.icon; 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, Eliademy.class); // 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, 0); notification.setLatestEventInfo(context, title, message, intent); notification.flags |= Notification.FLAG_AUTO_CANCEL; notificationManager.notify(0, notification); }