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:org.isoron.uhabits.HabitBroadcastReceiver.java
private void createNotification(Context context, Intent intent) { Uri data = intent.getData();//from w w w. ja va 2s . c o m Habit habit = Habit.get(ContentUris.parseId(data)); Long timestamp = intent.getLongExtra("timestamp", DateHelper.getStartOfToday()); Long reminderTime = intent.getLongExtra("reminderTime", DateHelper.getStartOfToday()); if (habit == null) return; if (habit.repetitions.hasImplicitRepToday()) return; habit.highlight = 1; habit.save(); if (!checkWeekday(intent, habit)) return; // Check if reminder has been turned off after alarm was scheduled if (habit.reminderHour == null) return; Intent contentIntent = new Intent(context, MainActivity.class); contentIntent.setData(data); PendingIntent contentPendingIntent = PendingIntent.getActivity(context, 0, contentIntent, 0); PendingIntent dismissPendingIntent = buildDismissIntent(context); PendingIntent checkIntentPending = buildCheckIntent(context, habit, timestamp); PendingIntent snoozeIntentPending = buildSnoozeIntent(context, habit); Uri soundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); NotificationCompat.WearableExtender wearableExtender = new NotificationCompat.WearableExtender() .setBackground(BitmapFactory.decodeResource(context.getResources(), R.drawable.stripe)); Notification notification = new NotificationCompat.Builder(context).setSmallIcon(R.drawable.ic_notification) .setContentTitle(habit.name).setContentText(habit.description) .setContentIntent(contentPendingIntent).setDeleteIntent(dismissPendingIntent) .addAction(R.drawable.ic_action_check, context.getString(R.string.check), checkIntentPending) .addAction(R.drawable.ic_action_snooze, context.getString(R.string.snooze), snoozeIntentPending) .setSound(soundUri).extend(wearableExtender).setWhen(reminderTime).setShowWhen(true).build(); notification.flags |= Notification.FLAG_AUTO_CANCEL; NotificationManager notificationManager = (NotificationManager) context .getSystemService(Activity.NOTIFICATION_SERVICE); int notificationId = (int) (habit.getId() % Integer.MAX_VALUE); notificationManager.notify(notificationId, notification); }
From source file:com.freshplanet.nativeExtensions.C2DMBroadcastReceiver.java
/** * Get the parameters from the message and create a notification from it. * @param context/*from ww w . j a va2 s . c om*/ * @param intent */ public void handleMessage(Context context, Intent intent) { try { registerResources(context); extractColors(context); FREContext ctxt = C2DMExtension.context; NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); // icon is required for notification. // @see http://developer.android.com/guide/practices/ui_guidelines/icon_design_status_bar.html int icon = notificationIcon; long when = System.currentTimeMillis(); // json string String parameters = intent.getStringExtra("parameters"); String facebookId = null; JSONObject object = null; if (parameters != null) { try { object = (JSONObject) new JSONTokener(parameters).nextValue(); } catch (Exception e) { Log.d(TAG, "cannot parse the object"); } } if (object != null && object.has("facebookId")) { facebookId = object.getString("facebookId"); } CharSequence tickerText = intent.getStringExtra("tickerText"); CharSequence contentTitle = intent.getStringExtra("contentTitle"); CharSequence contentText = intent.getStringExtra("contentText"); Intent notificationIntent = new Intent(context, Class.forName(context.getPackageName() + ".AppEntry")); PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, 0); Notification notification = new Notification(icon, tickerText, when); notification.flags |= Notification.FLAG_AUTO_CANCEL; notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent); RemoteViews contentView = new RemoteViews(context.getPackageName(), customLayout); contentView.setTextViewText(customLayoutTitle, contentTitle); contentView.setTextViewText(customLayoutDescription, contentText); contentView.setTextColor(customLayoutTitle, notification_text_color); contentView.setFloat(customLayoutTitle, "setTextSize", notification_title_size_factor * notification_text_size); contentView.setTextColor(customLayoutDescription, notification_text_color); contentView.setFloat(customLayoutDescription, "setTextSize", notification_description_size_factor * notification_text_size); if (facebookId != null) { Log.d(TAG, "bitmap not null"); CreateNotificationTask cNT = new CreateNotificationTask(); cNT.setParams(customLayoutImageContainer, NotifId, nm, notification, contentView); String src = "http://graph.facebook.com/" + facebookId + "/picture?type=normal"; URL url = new URL(src); cNT.execute(url); } else { Log.d(TAG, "bitmap null"); contentView.setImageViewResource(customLayoutImageContainer, customLayoutImage); notification.contentView = contentView; nm.notify(NotifId, notification); } NotifId++; if (ctxt != null) { parameters = parameters == null ? "" : parameters; ctxt.dispatchStatusEventAsync("COMING_FROM_NOTIFICATION", parameters); } } catch (Exception e) { Log.e(TAG, "Error activating application:", e); } }
From source file:com.manuelmazzuola.speedtogglebluetooth.service.MonitorSpeed.java
private void changeMessage(String message) { NotificationManager notificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); Intent stopIntent = new Intent(this, MainActivity.class); stopIntent.putExtra("close", "close"); PendingIntent stopPendingIntent = PendingIntent.getActivity(this, 0, stopIntent, PendingIntent.FLAG_UPDATE_CURRENT); NotificationCompat.Builder note = new NotificationCompat.Builder(this).setContentTitle(DEFAULT_TITLE) .setContentText(message).setAutoCancel(true).setContentIntent(stopPendingIntent) .setSmallIcon(R.drawable.ic_action_bluetooth); note.getNotification().flags |= Notification.FLAG_AUTO_CANCEL; Notification notification = note.build(); notification.flags = Notification.DEFAULT_LIGHTS | Notification.FLAG_AUTO_CANCEL; notificationManager.notify(intentId, notification); }
From source file:foam.zizim.android.BoskoiService.java
private void showNotification(String tickerText) { // This is what should be launched if the user selects our notification. Intent baseIntent = new Intent(this, IncidentsTab.class); baseIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); PendingIntent contentIntent = PendingIntent.getActivity(this, 0, baseIntent, 0); // choose the ticker text newBoskoiReportNotification = new Notification(R.drawable.favicon, tickerText, System.currentTimeMillis()); newBoskoiReportNotification.contentIntent = contentIntent; newBoskoiReportNotification.flags = Notification.FLAG_AUTO_CANCEL; newBoskoiReportNotification.defaults = Notification.DEFAULT_ALL; newBoskoiReportNotification.setLatestEventInfo(this, TAG, tickerText, contentIntent); if (ringtone) { // set the ringer Uri ringURI = Uri.fromFile(new File("/system/media/audio/ringtones/ringer.mp3")); newBoskoiReportNotification.sound = ringURI; }/*from w ww. jav a 2 s . c om*/ if (vibrate) { double vibrateLength = 100 * Math.exp(0.53 * 20); long[] vibrate = new long[] { 100, 100, (long) vibrateLength }; newBoskoiReportNotification.vibrate = vibrate; if (flashLed) { int color = Color.BLUE; newBoskoiReportNotification.ledARGB = color; } newBoskoiReportNotification.ledOffMS = (int) vibrateLength; newBoskoiReportNotification.ledOnMS = (int) vibrateLength; newBoskoiReportNotification.flags = newBoskoiReportNotification.flags | Notification.FLAG_SHOW_LIGHTS; } mNotificationManager.notify(NOTIFICATION_ID, newBoskoiReportNotification); }
From source file:vn.seasoft.sachcuatui.GCMService.GCMIntentService.java
private void sendNotification(String msg, Book book) { mNotificationManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE); Intent intent;/*from w ww . java 2 s . com*/ if (book == null) { intent = new Intent(this, MainActivity.class); } else { intent = new Intent(this, actInfoBook.class); intent.putExtra("idbook", book.getIdbook()); intent.putExtra("titlebook", book.getTitle()); intent.putExtra("authorbook", book.getAuthor()); intent.putExtra("countview", book.getCountview()); intent.putExtra("countdownload", book.getCountdownload()); intent.putExtra("idcategory", book.getIdcategory()); intent.putExtra("summary", book.getSummary()); intent.putExtra("cover", book.getImagecover()); } intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP); PendingIntent contentIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.ic_launcher).setContentTitle("Sch Ca Tui") .setStyle(new NotificationCompat.BigTextStyle().bigText(msg)).setContentText(msg); mBuilder.setAutoCancel(true); mBuilder.setContentIntent(contentIntent); Notification notification = mBuilder.build(); notification.flags |= Notification.FLAG_AUTO_CANCEL; notification.defaults |= Notification.DEFAULT_SOUND; notification.defaults |= Notification.DEFAULT_LIGHTS; mNotificationManager.notify(NOTIFICATION_ID, notification); }
From source file:com.maass.android.imgur_uploader.ImgurUpload.java
private void handleResponse() { Log.i(this.getClass().getName(), "in handleResponse()"); // close progress notification mNotificationManager.cancel(NOTIFICATION_ID); String notificationMessage = getString(R.string.upload_success); // notification intent with result final Intent notificationIntent = new Intent(getBaseContext(), ImageDetails.class); if (mImgurResponse == null) { notificationMessage = getString(R.string.connection_failed); } else if (mImgurResponse.get("error") != null) { notificationMessage = getString(R.string.unknown_error) + mImgurResponse.get("error"); } else {// w w w .jav a 2s . c o m // create thumbnail if (mImgurResponse.get("image_hash").length() > 0) { createThumbnail(imageLocation); } // store result in database final HistoryDatabase histData = new HistoryDatabase(getBaseContext()); final SQLiteDatabase data = histData.getWritableDatabase(); final HashMap<String, String> dataToSave = new HashMap<String, String>(); dataToSave.put("delete_hash", mImgurResponse.get("delete_hash")); dataToSave.put("image_url", mImgurResponse.get("original")); final Uri imageUri = Uri .parse(getFilesDir() + "/" + mImgurResponse.get("image_hash") + THUMBNAIL_POSTFIX); dataToSave.put("local_thumbnail", imageUri.toString()); dataToSave.put("upload_time", "" + System.currentTimeMillis()); for (final Map.Entry<String, String> entry : dataToSave.entrySet()) { final ContentValues content = new ContentValues(); content.put("hash", mImgurResponse.get("image_hash")); content.put("key", entry.getKey()); content.put("value", entry.getValue()); data.insert("imgur_history", null, content); } //set intent to go to image details notificationIntent.putExtra("hash", mImgurResponse.get("image_hash")); notificationIntent.putExtra("image_url", mImgurResponse.get("original")); notificationIntent.putExtra("delete_hash", mImgurResponse.get("delete_hash")); notificationIntent.putExtra("local_thumbnail", imageUri.toString()); data.close(); histData.close(); // if the main activity is already open then refresh the gridview sendBroadcast(new Intent(BROADCAST_ACTION)); } //assemble notification final Notification notification = new Notification(R.drawable.icon, notificationMessage, System.currentTimeMillis()); notification.setLatestEventInfo(this, getString(R.string.app_name), notificationMessage, PendingIntent .getActivity(getBaseContext(), 0, notificationIntent, PendingIntent.FLAG_CANCEL_CURRENT)); notification.flags |= Notification.FLAG_AUTO_CANCEL; mNotificationManager.notify(NOTIFICATION_ID, notification); }
From source file:org.transdroid.service.UpdateService.java
private void newNotification(String ticker, String title, String text, String downloadUrl, int notifyID) { // Use the alarm service settings for the notification sound/vibrate/colour SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()); AlarmSettings settings = Preferences.readAlarmSettings(prefs); // Set up an intent that will initiate a download of the new version Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse(downloadUrl)); // Create a new notification Notification newNotification = new Notification(R.drawable.icon_notification, ticker, System.currentTimeMillis()); newNotification.flags = Notification.FLAG_AUTO_CANCEL; newNotification.setLatestEventInfo(getApplicationContext(), title, text, PendingIntent.getActivity(getApplicationContext(), notifyID, i, 0)); // Get the system notification manager, if not done so previously if (notificationManager == null) { notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); }/*from w w w. ja v a2 s . c o m*/ // If sound enabled add to notification if (settings.getAlarmPlaySound() && settings.getAlarmSoundURI() != null) { newNotification.sound = Uri.parse(settings.getAlarmSoundURI()); } // If vibration enabled add to notification if (settings.getAlarmVibrate()) { newNotification.defaults = Notification.DEFAULT_VIBRATE; } // Add coloured light; defaults to 0xff7dbb21 newNotification.ledARGB = settings.getAlarmColour(); newNotification.ledOnMS = 600; newNotification.ledOffMS = 1000; newNotification.flags |= Notification.FLAG_SHOW_LIGHTS; // Send notification notificationManager.notify(notifyID, newNotification); }
From source file:nl.johndekroon.dma.GCMIntentService.java
/** * Issues a notification to inform the user that server has sent a message. *//*from ww w .j a v a 2 s. c om*/ private static void generateNotification(Context context, String message) { int icon = R.drawable.ic_stat_gcm; 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, MainActivity.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); }
From source file:com.snappy.GCMIntentService.java
@SuppressWarnings("deprecation") public void triggerNotification(Context context, String message, String fromName, Bundle pushExtras, String messageData) {//from ww w . j a va2 s . c o m if (fromName != null) { final NotificationManager notificationManager = (NotificationManager) getSystemService( NOTIFICATION_SERVICE); Notification notification = new Notification(R.drawable.icon_notification, message, System.currentTimeMillis()); notification.number = mNotificationCounter + 1; mNotificationCounter = mNotificationCounter + 1; Intent intent = new Intent(this, SplashScreenActivity.class); intent.replaceExtras(pushExtras); intent.putExtra(Const.PUSH_INTENT, true); intent.setAction(Long.toString(System.currentTimeMillis())); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_FROM_BACKGROUND | Intent.FLAG_ACTIVITY_TASK_ON_HOME); PendingIntent pendingIntent = PendingIntent.getActivity(this, notification.number, intent, PendingIntent.FLAG_UPDATE_CURRENT); notification.setLatestEventInfo(this, context.getString(R.string.app_name), messageData, pendingIntent); notification.flags |= Notification.FLAG_AUTO_CANCEL; notification.defaults |= Notification.DEFAULT_VIBRATE; notification.defaults |= Notification.DEFAULT_SOUND; notification.defaults |= Notification.DEFAULT_LIGHTS; String notificationId = Double.toString(Math.random()); notificationManager.notify(notificationId, 0, notification); } Log.i(LOG_TAG, message); Log.i(LOG_TAG, fromName); }
From source file:be.vbsteven.bmtodesk.BackgroundSharingService.java
/** * shows notification when the sending succeeded *///from w w w. j a va2 s.c o m private void showSuccessfulSend() { if (Global.isHideConfirmation(this)) { nManager.cancelAll(); } else { Notification n = new Notification(R.drawable.icon, "Sending bookmark successful", System.currentTimeMillis()); n.flags = Notification.FLAG_AUTO_CANCEL; Intent i = new Intent(this, AfterSuccessfulSendActivity.class); i.putExtra(Global.EXTRA_TITLE, title); i.putExtra(Global.EXTRA_URL, url); PendingIntent p = PendingIntent.getActivity(this, 4, i, 0); n.setLatestEventInfo(this, "Bookmark to Desktop", "Sending bookmark successful", p); nManager.notify(3, n); } }