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.airbop.client.GCMIntentService.java
private static void generateNotification(Context context, String title, String message, String url, String large_icon) {/*from ww w .j av a2 s . c o m*/ int icon = R.drawable.ic_stat_gcm; long when = System.currentTimeMillis(); NotificationManager notificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); if ((title == null) || (title.equals(""))) { title = context.getString(R.string.app_name); } Intent notificationIntent = null; if ((url == null) || (url.equals(""))) { //just bring up the app notificationIntent = new Intent(context, DemoActivity.class); } else { //Launch the URL notificationIntent = new Intent(Intent.ACTION_VIEW); notificationIntent.setData(Uri.parse(url)); notificationIntent.addCategory(Intent.CATEGORY_BROWSABLE); } // 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 notification = new NotificationCompat.Builder(context).setContentTitle(title) .setContentText(message).setContentIntent(intent).setSmallIcon(icon) .setLargeIcon(decodeImage(large_icon)).setWhen(when) .setStyle(new NotificationCompat.BigTextStyle().bigText(message)).build(); notification.flags |= Notification.FLAG_AUTO_CANCEL; notificationManager.notify(0, notification); }
From source file:edu.umich.si.inteco.minuku.manager.MinukuNotificationManager.java
private Notification buildNotificationForNotificationEvent(ShowNotificationEvent aShowNotificationEvent, Integer id) {/*from www . ja va 2 s . c o m*/ if (aShowNotificationEvent.getCreationTimeMs() == 0) { aShowNotificationEvent.setCreationTimeMs(new Date().getTime()); } Intent launchIntent = new Intent(this, aShowNotificationEvent.getViewToShow()); for (Map.Entry<String, String> entry : aShowNotificationEvent.getParams().entrySet()) { launchIntent.putExtra(entry.getKey(), entry.getValue()); } launchIntent.putExtra(Constants.TAPPED_NOTIFICATION_ID_KEY, id.toString()); //adding extra stuff to signify from notification code //launchIntent.putExtra("STARTED_FROM", "notification"); //keep this /*TaskStackBuilder stackBuilder = TaskStackBuilder.create(this); stackBuilder.addParentStack(aShowNotificationEvent.getViewToShow()); stackBuilder.addNextIntent(launchIntent);*/ //keep this PendingIntent pIntent = PendingIntent.getActivity(this, 0, launchIntent, PendingIntent.FLAG_UPDATE_CURRENT); //keep this /*PendingIntent pIntent = TaskStackBuilder.create(this) .addParentStack(aShowNotificationEvent.getViewToShow()) .addNextIntent(launchIntent) .getPendingIntent(0, PendingIntent.FLAG_CANCEL_CURRENT);*/ // PendingIntent.getActivity(this, // 0, launchIntent, PendingIntent.FLAG_CANCEL_CURRENT); Notification n = new Notification.Builder(this).setContentTitle(aShowNotificationEvent.getTitle()) .setContentIntent(pIntent).setContentText(aShowNotificationEvent.getMessage()) .setSmallIcon(aShowNotificationEvent.getIconID()).setAutoCancel(true).build(); n.flags = Notification.DEFAULT_LIGHTS | Notification.FLAG_AUTO_CANCEL; return n; }
From source file:name.gumartinm.weather.information.notification.NotificationIntentService.java
private void showNotification(final Current current, final WeatherLocation weatherLocation) { // 1. Update units of measurement. final UnitsConversor tempUnitsConversor = new TempUnitsConversor(this.getApplicationContext()); // 2. Formatters final DecimalFormat tempFormatter = (DecimalFormat) NumberFormat.getNumberInstance(Locale.US); tempFormatter.applyPattern("###.##"); // 3. Prepare data for RemoteViews. String tempMax = ""; if (current.getMain().getTemp_max() != null) { double conversion = (Double) current.getMain().getTemp_max(); conversion = tempUnitsConversor.doConversion(conversion); tempMax = tempFormatter.format(conversion) + tempUnitsConversor.getSymbol(); }//from w ww.jav a 2 s .co m String tempMin = ""; if (current.getMain().getTemp_min() != null) { double conversion = (Double) current.getMain().getTemp_min(); conversion = tempUnitsConversor.doConversion(conversion); tempMin = tempFormatter.format(conversion) + tempUnitsConversor.getSymbol(); } Bitmap picture; if ((current.getWeather().size() > 0) && (current.getWeather().get(0).getIcon() != null) && (IconsList.getIcon(current.getWeather().get(0).getIcon()) != null)) { final String icon = current.getWeather().get(0).getIcon(); picture = BitmapFactory.decodeResource(this.getResources(), IconsList.getIcon(icon).getResourceDrawable()); } else { picture = BitmapFactory.decodeResource(this.getResources(), R.drawable.weather_severe_alert); } final String city = weatherLocation.getCity(); final String country = weatherLocation.getCountry(); // 4. Insert data in RemoteViews. final RemoteViews remoteView = new RemoteViews(this.getApplicationContext().getPackageName(), R.layout.weather_notification); remoteView.setImageViewBitmap(R.id.weather_notification_image, picture); remoteView.setTextViewText(R.id.weather_notification_temperature_max, tempMax); remoteView.setTextViewText(R.id.weather_notification_temperature_min, tempMin); remoteView.setTextViewText(R.id.weather_notification_city, city); remoteView.setTextViewText(R.id.weather_notification_country, country); // 5. Activity launcher. final Intent resultIntent = new Intent(this.getApplicationContext(), MainTabsActivity.class); // The PendingIntent to launch our activity if the user selects this notification. // 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. final TaskStackBuilder stackBuilder = TaskStackBuilder.create(this.getApplicationContext()); // Adds the back stack for the Intent (but not the Intent itself) stackBuilder.addParentStack(MainTabsActivity.class); // Adds the Intent that starts the Activity to the top of the stack stackBuilder.addNextIntent(resultIntent); final PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); final NotificationManagerCompat notificationManager = NotificationManagerCompat .from(this.getApplicationContext()); // 6. Create notification. final NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder( this.getApplicationContext()).setContent(remoteView).setSmallIcon(R.drawable.ic_launcher) .setAutoCancel(true).setLocalOnly(true).setWhen(System.currentTimeMillis()) .setContentIntent(resultPendingIntent).setPriority(NotificationCompat.PRIORITY_DEFAULT); final Notification notification = notificationBuilder.build(); notification.flags |= Notification.FLAG_AUTO_CANCEL; // Send the notification. // Sets an ID for the notification, so it can be updated (just in case) int notifyID = 1; notificationManager.notify(notifyID, notification); }
From source file:org.croudtrip.location.LocationUploadTimerReceiver.java
private void handleError(Context context) { int fc = failureCount.incrementAndGet(); Timber.d("Failure Count is " + fc); if (fc == MAX_FAILURE_COUNT) { // show a notification that no position upload was possible NotificationManager notificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); Notification notification = new NotificationCompat.Builder(context) .setSmallIcon(R.drawable.ic_directions_car_white) .setContentTitle(context.getString(R.string.error_position_update_title)) .setStyle(new NotificationCompat.BigTextStyle() .bigText(context.getString(R.string.error_position_update_message))) .setContentText(context.getString(R.string.error_position_update_message)).build(); notification.flags |= Notification.FLAG_AUTO_CANCEL; notificationManager.notify(NOTIFICATION_UPLOAD_TIMER, notification); }//from w ww .ja va 2 s . c o m }
From source file:com.frostwire.android.gui.services.EngineService.java
public void notifyDownloadFinished(String displayName, File file, String infoHash) { try {//from www. j av a 2 s . co m if (notifiedStorage.contains(infoHash)) { // already notified return; } else { notifiedStorage.add(infoHash); } Context context = getApplicationContext(); Intent i = new Intent(context, MainActivity.class); i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP); i.putExtra(Constants.EXTRA_DOWNLOAD_COMPLETE_NOTIFICATION, true); i.putExtra(Constants.EXTRA_DOWNLOAD_COMPLETE_PATH, file.getAbsolutePath()); PendingIntent pi = PendingIntent.getActivity(context, 0, i, PendingIntent.FLAG_UPDATE_CURRENT); NotificationManager manager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); Notification notification = new NotificationCompat.Builder(context, Constants.FROSTWIRE_NOTIFICATION_CHANNEL_ID).setWhen(System.currentTimeMillis()) .setContentText(getString(R.string.download_finished)) .setContentTitle(getString(R.string.download_finished)) .setSmallIcon(getNotificationIcon()).setContentIntent(pi).build(); notification.vibrate = ConfigurationManager.instance().vibrateOnFinishedDownload() ? VENEZUELAN_VIBE : null; notification.number = TransferManager.instance().getDownloadsToReview(); notification.flags |= Notification.FLAG_AUTO_CANCEL; if (manager != null) { if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) { NotificationChannel channel = new NotificationChannel( Constants.FROSTWIRE_NOTIFICATION_CHANNEL_ID, "FrostWire", NotificationManager.IMPORTANCE_MIN); channel.setSound(null, null); manager.createNotificationChannel(channel); } manager.notify(Constants.NOTIFICATION_DOWNLOAD_TRANSFER_FINISHED, notification); } } catch (Throwable e) { LOG.error("Error creating notification for download finished", e); } }
From source file:nl.sogeti.android.gpstracker.actions.NameTrack.java
private void startDelayNotification() { int resId = R.string.dialog_routename_title; int icon = R.drawable.ic_maps_indicator_current_position; CharSequence tickerText = getResources().getString(resId); long when = System.currentTimeMillis(); Notification nameNotification = new Notification(icon, tickerText, when); nameNotification.flags |= Notification.FLAG_AUTO_CANCEL; CharSequence contentTitle = getResources().getString(R.string.app_name); CharSequence contentText = getResources().getString(resId); Intent notificationIntent = new Intent(this, NameTrack.class); notificationIntent.setData(mTrackUri); PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, Intent.FLAG_ACTIVITY_NEW_TASK); nameNotification.setLatestEventInfo(this, contentTitle, contentText, contentIntent); NotificationManager noticationManager = (NotificationManager) this .getSystemService(Context.NOTIFICATION_SERVICE); noticationManager.notify(R.layout.namedialog, nameNotification); }
From source file:cm.aptoide.pt.DownloadQueueService.java
private void setFinishedNotification(int apkidHash, String localPath) { String apkid = notifications.get(apkidHash).get("apkid"); int size = Integer.parseInt(notifications.get(apkidHash).get("intSize")); String version = notifications.get(apkidHash).get("version"); RemoteViews contentView = new RemoteViews(getPackageName(), R.layout.download_notification); contentView.setImageViewResource(R.id.download_notification_icon, R.drawable.ic_notification); contentView.setTextViewText(R.id.download_notification_name, getString(R.string.finished_download_message) + " " + apkid + " v." + version); contentView.setProgressBar(R.id.download_notification_progress_bar, size * KBYTES_TO_BYTES, size * KBYTES_TO_BYTES, false); Intent onClick = new Intent("pt.caixamagica.aptoide.INSTALL_APK", Uri.parse("apk:" + apkid)); onClick.setClassName("cm.aptoide.pt", "cm.aptoide.pt.RemoteInTab"); onClick.setFlags(Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT | Intent.FLAG_ACTIVITY_NEW_TASK); onClick.putExtra("localPath", localPath); onClick.putExtra("apkid", apkid); onClick.putExtra("apkidHash", apkidHash); onClick.putExtra("isUpdate", Boolean.parseBoolean(notifications.get(apkid.hashCode()).get("isUpdate"))); /*Changed by Rafael Campos*/ onClick.putExtra("version", notifications.get(apkid.hashCode()).get("version")); Log.d("Aptoide-DownloadQueuService", "finished notification apkidHash: " + apkidHash + " localPath: " + localPath); // The PendingIntent to launch our activity if the user selects this notification PendingIntent onClickAction = PendingIntent.getActivity(context, 0, onClick, 0); Notification notification = new Notification(R.drawable.ic_notification, getString(R.string.finished_download_alrt) + " " + apkid, System.currentTimeMillis()); notification.flags |= Notification.FLAG_AUTO_CANCEL; notification.contentView = contentView; // Set the info for the notification panel. notification.contentIntent = onClickAction; // notification.setLatestEventInfo(this, getText(R.string.app_name), getText(R.string.add_repo_text), contentIntent); notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); // Send the notification. // We use the position because it is a unique number. We use it later to cancel. notificationManager.notify(apkidHash, notification); // Log.d("Aptoide-DownloadQueueService", "Notification Set"); }
From source file:org.mythdroid.util.UpdateService.java
private void checkMythDroid() { if (MDVer == null) return;/*from ww w. j a v a 2 s . co m*/ Version runningVer; try { runningVer = new Version(getPackageManager().getPackageInfo(getPackageName(), 0).versionName, null); } catch (NameNotFoundException e) { return; } if (runningVer.compareTo(MDVer) >= 0) { LogUtil.debug("Already running latest version of MythDroid"); //$NON-NLS-1$ return; } LogUtil.debug("Version " + MDVer.toString() + //$NON-NLS-1$ " is available (current version is " + runningVer.toString() + ")" //$NON-NLS-1$ //$NON-NLS-2$ ); final NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); final Notification notification = new Notification(R.drawable.logo, Messages.getString("UpdateService.0") + "MythDroid" + //$NON-NLS-1$ //$NON-NLS-2$ Messages.getString("UpdateService.1"), //$NON-NLS-1$ System.currentTimeMillis()); notification.flags = Notification.FLAG_AUTO_CANCEL; final Intent intent = new Intent(MDACTION); intent.putExtra(VER, MDVer.toString()); intent.putExtra(URL, MDVer.url.toString()); notification.setLatestEventInfo(getApplicationContext(), "MythDroid" + Messages.getString("UpdateService.2"), //$NON-NLS-1$ //$NON-NLS-2$ MDVer.toString() + Messages.getString("UpdateService.1") + //$NON-NLS-1$ Messages.getString("UpdateService.3"), //$NON-NLS-1$ PendingIntent.getBroadcast(this, 0, intent, 0)); nm.notify(CHECKMD, notification); }
From source file:com.airbop.library.simple.AirBopGCMIntentService.java
/** * Issues a notification to inform the user that server has sent a message. *//*from w w w . jav a 2 s. c om*/ private static void generateNotification(Context context, String title, String message) { AirBopManifestSettings airBop_settings = CommonUtilities.loadDataFromManifest(context); //int icon = R.drawable.ic_stat_gcm; int icon = 0; Resources res = context.getResources(); if (res != null) { //icon = res.getIdentifier(airBop_settings.mDefaultNotificationIcon, null, null); icon = airBop_settings.mNotificationIcon; } long when = System.currentTimeMillis(); NotificationManager notificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); //if ((title == null) || (title.equals(""))) { if (title == null) { title = airBop_settings.mDefaultNotificationTitle; } Class intent_class = null; if (context != null) { ClassLoader class_loader = context.getClassLoader(); if (class_loader != null) { try { if (airBop_settings.mDefaultNotificationClass != null) { intent_class = Class.forName(airBop_settings.mDefaultNotificationClass); } } catch (ClassNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } //Log.i(TAG, "intent_class: " + intent_class); } } Intent notificationIntent = null; if (intent_class != null) { notificationIntent = new Intent(context, intent_class); } else { notificationIntent = new Intent(Intent.ACTION_VIEW); } // 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 notification = new NotificationCompat.Builder(context).setContentTitle(title) .setContentText(message).setContentIntent(intent).setSmallIcon(icon).setWhen(when) .setStyle(new NotificationCompat.BigTextStyle().bigText(message)).build(); notification.flags |= Notification.FLAG_AUTO_CANCEL; notificationManager.notify(0, notification); }
From source file:com.geomoby.geodeals.DemoService.java
/** * Issues a notification to inform the user that server has sent a message. */// w w w.ja v a 2 s .c o m private static void generateNotification(Context context, String message) { if (message.length() > 0) { // Parse the GeoMoby message using the GeoMessage class try { Gson gson = new Gson(); JsonParser parser = new JsonParser(); JsonArray Jarray = parser.parse(message).getAsJsonArray(); ArrayList<GeoMessage> alerts = new ArrayList<GeoMessage>(); for (JsonElement obj : Jarray) { GeoMessage gName = gson.fromJson(obj, GeoMessage.class); alerts.add(gName); } // Prepare Notification and pass the GeoMessage to an Extra NotificationManager notificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); Intent i = new Intent(context, CustomNotification.class); i.putParcelableArrayListExtra("GeoMessage", (ArrayList<GeoMessage>) alerts); PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, i, PendingIntent.FLAG_UPDATE_CURRENT); // Read from the /assets directory Resources resources = context.getResources(); AssetManager assetManager = resources.getAssets(); try { InputStream inputStream = assetManager.open("geomoby.properties"); Properties properties = new Properties(); properties.load(inputStream); String push_icon = properties.getProperty("push_icon"); int icon = resources.getIdentifier(push_icon, "drawable", context.getPackageName()); int not_title = resources.getIdentifier("notification_title", "string", context.getPackageName()); int not_text = resources.getIdentifier("notification_text", "string", context.getPackageName()); int not_ticker = resources.getIdentifier("notification_ticker", "string", context.getPackageName()); // Manage notifications differently according to Android version if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { NotificationCompat.Builder builder = new NotificationCompat.Builder(context); builder.setSmallIcon(icon).setContentTitle(context.getResources().getText(not_title)) .setContentText(context.getResources().getText(not_text)) .setTicker(context.getResources().getText(not_ticker)) .setContentIntent(pendingIntent).setAutoCancel(true); builder.setDefaults(Notification.DEFAULT_ALL); //Vibrate, Sound and Led // Because the ID remains unchanged, the existing notification is updated. notificationManager.notify(notifyID, builder.build()); } else { Notification notification = new Notification(icon, context.getResources().getText(not_text), System.currentTimeMillis()); //Setting Notification Flags notification.defaults |= Notification.DEFAULT_ALL; notification.flags |= Notification.FLAG_AUTO_CANCEL; //Set the Notification Info notification.setLatestEventInfo(context, context.getResources().getText(not_text), context.getResources().getText(not_ticker), pendingIntent); //Send the notification // Because the ID remains unchanged, the existing notification is updated. notificationManager.notify(notifyID, notification); } } catch (IOException e) { System.err.println("Failed to open geomoby property file"); e.printStackTrace(); } } catch (JsonParseException e) { Log.i(TAG, "This is not a GeoMoby notification"); throw new RuntimeException(e); } } }