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.evandroid.musica.services.BatchDownloaderService.java
private void updateProgress() { NotificationManager manager = ((NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE)); if (count < total) { NotificationCompat.Builder notifBuilder = new NotificationCompat.Builder(this); notifBuilder.setSmallIcon(android.R.drawable.stat_sys_download) .setContentTitle(getString(R.string.app_name)) .setContentText(String.format(getString(R.string.dl_progress), count, total)) .setProgress(total, count, false).setShowWhen(false); Notification notif = notifBuilder.build(); notif.flags |= Notification.FLAG_NO_CLEAR | Notification.FLAG_ONGOING_EVENT; if (count == 0) startForeground(1, notif);/*www . ja v a 2s.c o m*/ else manager.notify(1, notif); } else { stopForeground(true); Intent refreshIntent = new Intent("com.geecko.QuickLyric.updateDBList"); PendingIntent pendingIntent = PendingIntent.getActivity(getBaseContext(), 4, refreshIntent, PendingIntent.FLAG_ONE_SHOT); String text = getResources().getQuantityString(R.plurals.dl_finished_desc, successCount, successCount); NotificationCompat.Builder notifBuilder = new NotificationCompat.Builder(this); notifBuilder.setSmallIcon(android.R.drawable.stat_sys_download_done); notifBuilder.setContentIntent(pendingIntent); notifBuilder.setContentTitle(getString(R.string.dl_finished)); notifBuilder.setContentText(text); Notification notif = notifBuilder.build(); notif.flags |= Notification.FLAG_AUTO_CANCEL; manager.notify(1, notif); stopSelf(); } }
From source file:be.vbsteven.bmtodesk.BackgroundSharingService.java
/** * shows notification when the sending failed * * @param message//from www. j a va2 s . c om */ private void showFailedSend(String message) { Notification n = new Notification(R.drawable.icon, "Sending bookmark failed", System.currentTimeMillis()); n.flags = Notification.FLAG_AUTO_CANCEL; Intent i = new Intent(this, ShareActivity.class); i.putExtra(Global.EXTRA_TITLE, title); i.putExtra(Global.EXTRA_URL, url); PendingIntent p = PendingIntent.getActivity(this, 4, i, 0); n.setLatestEventInfo(this, "Sending bookmark failed", message, p); nManager.notify(3, n); }
From source file:mdn.vtvsport.GcmIntentService.java
private static void generateNotification(Context context, GCMInfo info) { /*/* ww w. ja va2 s .c o m*/ int icon = R.drawable.icon_small; long when = System.currentTimeMillis(); NotificationManager notificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); Notification notification = new Notification(icon, info.getMessage(), when); String title = context.getString(R.string.app_name); Intent notificationIntent = new Intent(context, BaseSlideMenuActivity.class); notificationIntent.putExtra(GCMBUNDLE_ID, info.getItemId()); notificationIntent.putExtra(GCMBUNDLE_TYPE, info.getType()); // 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, info.getMessage(), intent); notification.flags |= Notification.FLAG_AUTO_CANCEL; notificationManager.notify(0, notification); */ String message = info.getMessage(); Intent notificationIntent = new Intent(context, BaseSlideMenuActivity.class); notificationIntent.putExtra(GCMBUNDLE_ID, info.getItemId()); notificationIntent.putExtra(GCMBUNDLE_TYPE, info.getType()); notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);//FLAG_ACTIVITY_NEW_TASK TaskStackBuilder stackBuilder = TaskStackBuilder.create(context); stackBuilder.addParentStack(BaseSlideMenuActivity.class); stackBuilder.addNextIntent(notificationIntent); int id = -1; try { id = Integer.parseInt(info.getMessageId()); } catch (Exception e) { // TODO: handle exception } PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(id, PendingIntent.FLAG_CANCEL_CURRENT); NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context).setTicker(message) .setSmallIcon(R.drawable.icon_small).setContentTitle(HomeFragment.APP_NAME_1) .setContentText(message).setAutoCancel(true).setContentIntent(resultPendingIntent) .setStyle(new NotificationCompat.BigTextStyle().setSummaryText(message)); NotificationManager mNotificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); Notification notification = mBuilder.build(); notification.flags |= Notification.FLAG_NO_CLEAR | Notification.FLAG_AUTO_CANCEL; mNotificationManager.notify(id, notification); }
From source file:edu.oakland.cse480.GCMIntentService.java
public void sendCustNotification(String incomingMsg) { Log.i("incomingMsg = ", "" + incomingMsg); int msgCode;//from w w w .j av a2 s .co m try { msgCode = Character.getNumericValue(incomingMsg.charAt(0)); } catch (Exception e) { msgCode = 0; } String msg; //String[] separated = incomingMsg.split("|"); //separated[0] = separated[0]; //discard //separated[1] = separated[1] + ""; //separated[2] = separated[2] + ""; //Additional message with "" to negate a null boolean showNotification = true; Intent intent; switch (msgCode) { case 1: msg = "A new player joined the game"; intent = new Intent("UpdateGameLobby"); intent.putExtra("GAMESTARTED", false); this.sendBroadcast(intent); break; case 2: msg = "The game has started"; intent = new Intent("UpdateGameLobby"); intent.putExtra("GAMESTARTED", true); this.sendBroadcast(intent); break; case 3: msg = "It is your turn to bet"; intent = new Intent("UpdateGamePlay"); this.sendBroadcast(intent); //Stuff break; case 4: msg = "Flop goes"; break; case 5: msg = "A card has been dealt"; //Stuff break; case 6: msg = "The river card, has been dealt"; //Stuff break; case 7: msg = "Hand is over. Winner was " + incomingMsg.substring(1); intent = new Intent("UpdateGamePlay"); intent.putExtra("WINNER", "Winner of last hand: " + incomingMsg.substring(1)); this.sendBroadcast(intent); //Stuff break; case 8: msg = "Game is over. Winner was " + incomingMsg.substring(1); intent = new Intent("UpdateGamePlay"); intent.putExtra("WINNER", "Winner of Game: " + incomingMsg.substring(1)); this.sendBroadcast(intent); //Stuff break; default: msg = "Switch case isn't working"; showNotification = false; //Some default stuff break; } if (showNotification) { mNotificationManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE); Intent newIntent = new Intent(this, Gameplay.class); newIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); PendingIntent contentIntent = PendingIntent.getActivity(this, 0, newIntent, 0); NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.ic_launcher).setContentTitle("Poker Notification") .setStyle(new NotificationCompat.BigTextStyle().bigText(msg)).setContentText(msg); mBuilder.setContentIntent(contentIntent); Notification notification = mBuilder.build(); notification.defaults |= Notification.DEFAULT_LIGHTS | Notification.DEFAULT_SOUND | Notification.DEFAULT_VIBRATE; notification.flags |= Notification.FLAG_AUTO_CANCEL | Notification.FLAG_SHOW_LIGHTS; mNotificationManager.notify(NOTIFICATION_ID, notification); } }
From source file:com.rampgreen.caretakermobile.GcmIntentService.java
private void sendNotification(String notificationTitle, String msg) { mNotificationManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE); Bundle bundle = new Bundle(); bundle.putString(Constants.NOTIFICATION_MSG, msg); bundle.putString(Constants.CALLED_COMPONENT, Constants.SERVICE_GCM_INTENT); Intent notificationIntent = new Intent(this, ActivityNotification.class); notificationIntent.putExtras(bundle); notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK); PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0); NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.ic_launcher).setContentTitle(notificationTitle) .setStyle(new NotificationCompat.BigTextStyle().bigText(msg)).setContentText(msg); mBuilder.setContentIntent(contentIntent); Notification notification = mBuilder.build(); notification.flags |= Notification.FLAG_AUTO_CANCEL; mNotificationManager.notify(NOTIFICATION_ID, notification); }
From source file:de.tudarmstadt.dvs.myhealthassistant.myhealthhub.services.SensorModuleManager.java
@Override public int onStartCommand(Intent i, int flags, int startId) { // Log.e(TAG, // "call me redundant BABY! onStartCommand service"); Intent intent = new Intent(this, MyHealthHubWithFragments.class); PendingIntent pendIntent = PendingIntent.getActivity(this, 0, intent, 0); int myID = android.os.Process.myPid(); Notification notice = new Notification.Builder(getApplicationContext()).setSmallIcon(R.drawable.ic_launcher) .setWhen(System.currentTimeMillis()).setContentTitle(getPackageName()) .setContentText(TAG + " running").setContentIntent(pendIntent).getNotification(); notice.flags |= Notification.FLAG_AUTO_CANCEL; startForeground(myID, notice);/* w w w . j av a2 s.com*/ // Start sensor connections startAutoConnectSensorModules(); return START_STICKY; }
From source file:com.unfc.choicecustomercare.gcmservices.MyGcmListenerService.java
/** * Create and show a simple notification containing the received GCM * message.//from ww w . j a v a 2s .co m * * @param message GCM message received. */ private void sendNotification(String message) { Intent intent = new Intent(this, MainActivity.class); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_ONE_SHOT); Intent intentAccept = new Intent(this, MainActivity.class); intent.setAction("accept"); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); PendingIntent pendingAccept = PendingIntent.getActivity(this, 1, intentAccept, PendingIntent.FLAG_ONE_SHOT); // Intent intentDecline = new Intent(this, MainActivity.class); intent.setAction("decline"); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); PendingIntent pendingDecline = PendingIntent.getActivity(this, 2, intentDecline, PendingIntent.FLAG_ONE_SHOT); Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.mipmap.ic_launcher).setContentTitle(getString(R.string.app_name)) .setContentText(message).setAutoCancel(true).setSound(defaultSoundUri) .setContentIntent(pendingIntent).setAutoCancel(false) .addAction(R.drawable.accept_ico, "Accept", pendingAccept) .addAction(R.drawable.decline_ico, "Decline", pendingDecline); notificationBuilder.getNotification().flags |= Notification.FLAG_AUTO_CANCEL; notificationBuilder.setAutoCancel(true); NotificationManager notificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); notificationManager.notify((int) new Date().getTime(), notificationBuilder.build()); }
From source file:com.ta.truckmap.gpstracking.GcmIntentService.java
@SuppressWarnings("deprecation") private Notification createNotificationConstraints(PendingIntent contentIntent, int type) { Notification notification = new Notification(R.drawable.appicon, TAG, System.currentTimeMillis()); notification.setLatestEventInfo(this, getResources().getString(R.string.app_name), myMsg, contentIntent); notification.defaults |= Notification.DEFAULT_SOUND; long[] vibrate = { 0, 100, 200, 300 }; notification.vibrate = vibrate;/*ww w . ja va2 s.c om*/ notification.defaults |= Notification.DEFAULT_LIGHTS; notification.flags |= Notification.FLAG_AUTO_CANCEL; return notification; }
From source file:com.quarterfull.newsAndroid.services.DownloadImagesService.java
private Notification BuildNotification() { Intent intentNewsReader = new Intent(this, NewsReaderListActivity.class); PendingIntent pIntent = PendingIntent.getActivity(this, 0, intentNewsReader, 0); notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); mNotificationDownloadImages = new NotificationCompat.Builder(this) .setContentTitle(getResources().getString(R.string.app_name)) .setContentText("Downloading images for offline usage").setSmallIcon(R.drawable.ic_notification) .setContentIntent(pIntent).setOngoing(true); Notification notify = mNotificationDownloadImages.build(); //Hide the notification after its selected notify.flags |= Notification.FLAG_AUTO_CANCEL; notify.flags |= Notification.FLAG_NO_CLEAR; return notify; }