List of usage examples for android.app Notification FLAG_ONLY_ALERT_ONCE
int FLAG_ONLY_ALERT_ONCE
To view the source code for android.app Notification FLAG_ONLY_ALERT_ONCE.
Click Source Link
From source file:hmatalonga.greenhub.util.Notifier.java
public static void batteryHighTemperature(final Context context) { if (sNotificationManager == null) { sNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); }// w ww . ja v a 2s . c o m NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context) .setSmallIcon(R.drawable.ic_alert_circle_white_24dp).setContentTitle("Battery temperature is hot!") .setContentText("Cool-down your phone for a while").setAutoCancel(true).setOngoing(false) .setLights(Color.RED, 500, 2000).setVibrate(new long[] { 0, 800, 1500 }) .setPriority(SettingsUtils.fetchNotificationsPriority(context)); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { mBuilder.setVisibility(Notification.VISIBILITY_PUBLIC); } // Because the ID remains unchanged, the existing notification is updated. Notification notification = mBuilder.build(); notification.flags |= Notification.FLAG_ONLY_ALERT_ONCE; sNotificationManager.notify(Config.NOTIFICATION_TEMPERATURE_HIGH, notification); }
From source file:net.geniecode.ttr.ScheduleReceiver.java
@SuppressWarnings("deprecation") @SuppressLint("NewApi") private void setNotification(Context context) { ScrollingText = context.getString(R.string.schedule_postponed_scroll); NotificationText = context.getString(R.string.schedule_postponed_notify); // Trigger a notification that, when clicked, will activate airplane mode mNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); PendingIntent contentIntent = PendingIntent.getActivity(context, 0, new Intent(context, ActivateFlightMode.class), PendingIntent.FLAG_CANCEL_CURRENT); Notification notification;/*from w w w .j a va2 s . co m*/ if (android.os.Build.VERSION.SDK_INT >= 11) { Notification.Builder builder = new Notification.Builder(context); builder.setContentIntent(contentIntent).setSmallIcon(R.drawable.ic_launcher).setTicker(ScrollingText) .setWhen(System.currentTimeMillis()).setAutoCancel(true).setOnlyAlertOnce(true) .setDefaults(Notification.DEFAULT_LIGHTS).setContentTitle(context.getText(R.string.app_name)) .setContentText(NotificationText); if (android.os.Build.VERSION.SDK_INT >= 16) { notification = builder.build(); } else { notification = builder.getNotification(); } } else { notification = new Notification(R.drawable.ic_launcher, ScrollingText, System.currentTimeMillis()); notification.setLatestEventInfo(context, context.getText(R.string.app_name), NotificationText, contentIntent); notification.flags |= Notification.FLAG_ONLY_ALERT_ONCE | Notification.FLAG_AUTO_CANCEL; notification.defaults |= Notification.DEFAULT_LIGHTS; } mNotificationManager.notify(NOTIFICATION_ID, notification); }
From source file:com.bluelinelabs.logansquare.typeconverters.NotificationConverter.java
@TargetApi(Build.VERSION_CODES.KITKAT) @NonNull//from w w w .j a v a2 s .c om public static SimpleNotification toSimpleNotification(@NonNull Notification notification) { SimpleNotification simpleNotification = new SimpleNotification(); simpleNotification.autoCancel = (notification.flags & Notification.FLAG_AUTO_CANCEL) == Notification.FLAG_AUTO_CANCEL; android.util.Log.d("json2notification", "autoCancel:" + simpleNotification.autoCancel); //simpleNotification.bigPictureStyle // TODO simpleNotification.category = notification.category; simpleNotification.color = notification.color > 0 ? notification.color : null; simpleNotification.contentInfo = notification.extras.getString(Notification.EXTRA_INFO_TEXT); simpleNotification.contentIntent = notification.contentIntent; simpleNotification.contentTitle = notification.extras.getString(Notification.EXTRA_TITLE); simpleNotification.contentText = notification.extras.getString(Notification.EXTRA_TEXT); simpleNotification.defaults = notification.defaults > 0 ? notification.defaults : null; simpleNotification.deleteIntent = notification.deleteIntent; //simpleNotification.extras; simpleNotification.groupKey = notification.getGroup(); if (simpleNotification.groupKey != null) { simpleNotification.groupSummary = (notification.flags & Notification.FLAG_GROUP_SUMMARY) == Notification.FLAG_GROUP_SUMMARY; } Bitmap bitmap = notification.extras.getParcelable(Notification.EXTRA_LARGE_ICON); if (bitmap != null) simpleNotification.largeIcon = Bitmaps.base64(bitmap); if ((notification.flags & Notification.FLAG_SHOW_LIGHTS) == Notification.FLAG_SHOW_LIGHTS) { simpleNotification.lights = Arrays.asList(notification.ledARGB, notification.ledOnMS, notification.ledOffMS); } simpleNotification.localOnly = (notification.flags & Notification.FLAG_LOCAL_ONLY) == Notification.FLAG_LOCAL_ONLY; simpleNotification.number = notification.number > 0 ? notification.number : null; simpleNotification.ongoing = (notification.flags & Notification.FLAG_ONGOING_EVENT) == Notification.FLAG_ONGOING_EVENT; simpleNotification.onlyAlertOnce = (notification.flags & Notification.FLAG_ONLY_ALERT_ONCE) == Notification.FLAG_ONLY_ALERT_ONCE; String[] people = notification.extras.getStringArray(Notification.EXTRA_PEOPLE); if (people != null) { simpleNotification.people = Arrays.asList(people); } simpleNotification.priority = notification.priority > 0 ? notification.priority : null; //simpleNotification.progress; simpleNotification.publicVersion = notification.publicVersion; simpleNotification.showWhen = notification.extras.getBoolean(Notification.EXTRA_SHOW_WHEN); if (simpleNotification.showWhen) { simpleNotification.when = notification.when; } simpleNotification.smallIcon = String.valueOf(notification.extras.getInt(Notification.EXTRA_SMALL_ICON)); // TODO getResourceNameById() android.util.Log.d("json2notification", "simpleNotification.smallIcon" + simpleNotification.smallIcon); simpleNotification.sortKey = notification.getSortKey(); simpleNotification.sound = notification.sound; simpleNotification.subText = notification.extras.getString(Notification.EXTRA_SUB_TEXT); simpleNotification.tickerText = notification.tickerText; simpleNotification.usesChronometer = notification.extras.getBoolean(Notification.EXTRA_SHOW_CHRONOMETER); simpleNotification.visibility = notification.visibility > 0 ? notification.visibility : null; return simpleNotification; }
From source file:com.hmatalonga.greenhub.util.Notifier.java
public static void batteryWarningTemperature(final Context context) { if (sNotificationManager == null) { sNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); }//ww w . jav a 2s. c om NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context) .setSmallIcon(R.drawable.ic_alert_circle_white_24dp) .setContentTitle(context.getString(R.string.notif_battery_warning)) .setContentText(context.getString(R.string.notif_battery_warm)).setAutoCancel(true) .setOngoing(false).setLights(Color.YELLOW, 500, 2000).setVibrate(new long[] { 0, 400, 1000 }) .setPriority(SettingsUtils.fetchNotificationsPriority(context)); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { mBuilder.setVisibility(Notification.VISIBILITY_PUBLIC); } // Creates an explicit intent for an Activity in your app Intent resultIntent = new Intent(context, MainActivity.class); resultIntent.putExtra("tab", 2); // 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); // Adds the back stack for the Intent (but not the Intent itself) stackBuilder.addParentStack(InboxActivity.class); // Adds the Intent that starts the Activity to the top of the stack stackBuilder.addNextIntent(resultIntent); PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); mBuilder.setContentIntent(resultPendingIntent); // Because the ID remains unchanged, the existing notification is updated. Notification notification = mBuilder.build(); notification.flags |= Notification.FLAG_ONLY_ALERT_ONCE; sNotificationManager.notify(Config.NOTIFICATION_TEMPERATURE_WARNING, notification); }
From source file:cl.iluminadoschile.pako.floatingdiv.CustomOverlayService.java
@Override protected Notification foregroundNotification(int notificationId) { Notification notification;/*from www. ja va2s . c om*/ if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT && activation_method.equals(Constants.SETTINGS.ACTIVATION_METHOD_MANUAL)) { Intent settingsIntent = new Intent(Intent.ACTION_MAIN); settingsIntent.setClassName(Constants.ACTION.prefix, Constants.ACTION.prefix + ".SettingsActivity"); settingsIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK); PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, settingsIntent, 0); Intent startFgIntent = new Intent(this, CustomOverlayService.class); startFgIntent.setAction(Constants.ACTION.STARTFOREGROUND_ACTION); PendingIntent pstartFgIntent = PendingIntent.getService(this, 0, startFgIntent, 0); Intent pauseFgIntent = new Intent(this, CustomOverlayService.class); pauseFgIntent.setAction(Constants.ACTION.PAUSEFOREGROUND_ACTION); PendingIntent ppauseFgIntent = PendingIntent.getService(this, 0, pauseFgIntent, 0); Intent stopFgIntent = new Intent(this, CustomOverlayService.class); stopFgIntent.setAction(Constants.ACTION.STOPFOREGROUND_ACTION); PendingIntent pstopFgIntent = PendingIntent.getService(this, 0, stopFgIntent, 0); Bitmap icon = BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher); notification = new NotificationCompat.Builder(this) .setContentTitle(getString(R.string.title_notification)) .setTicker(getString(R.string.title_notification)) .setContentText(getString(R.string.message_notification)).setSmallIcon(R.drawable.ic_launcher) .setLargeIcon(Bitmap.createScaledBitmap(icon, 128, 128, false)).setContentIntent(pendingIntent) .setOngoing(true).addAction(android.R.drawable.ic_media_play, "Start", pstartFgIntent) .addAction(android.R.drawable.ic_media_pause, "Pause", ppauseFgIntent) .addAction(android.R.drawable.ic_delete, "Stop", pstopFgIntent).build(); } else { notification = new Notification(R.drawable.ic_launcher, getString(R.string.title_notification), System.currentTimeMillis()); notification.flags = notification.flags | Notification.FLAG_ONGOING_EVENT | Notification.FLAG_ONLY_ALERT_ONCE; notification.setLatestEventInfo(this, getString(R.string.title_notification), getString(R.string.message_notification_manual), notificationIntent()); } return notification; }
From source file:com.hmatalonga.greenhub.util.Notifier.java
public static void batteryHighTemperature(final Context context) { if (sNotificationManager == null) { sNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); }/* ww w . ja v a 2s. c om*/ NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context) .setSmallIcon(R.drawable.ic_alert_circle_white_24dp) .setContentTitle(context.getString(R.string.notif_battery_hot)) .setContentText(context.getString(R.string.notif_battery_cooldown)).setAutoCancel(true) .setOngoing(false).setLights(Color.RED, 500, 2000).setVibrate(new long[] { 0, 800, 1500 }) .setPriority(SettingsUtils.fetchNotificationsPriority(context)); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { mBuilder.setVisibility(Notification.VISIBILITY_PUBLIC); } // Creates an explicit intent for an Activity in your app Intent resultIntent = new Intent(context, MainActivity.class); resultIntent.putExtra("tab", 2); // 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); // Adds the back stack for the Intent (but not the Intent itself) stackBuilder.addParentStack(InboxActivity.class); // Adds the Intent that starts the Activity to the top of the stack stackBuilder.addNextIntent(resultIntent); PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); mBuilder.setContentIntent(resultPendingIntent); // Because the ID remains unchanged, the existing notification is updated. Notification notification = mBuilder.build(); notification.flags |= Notification.FLAG_ONLY_ALERT_ONCE; sNotificationManager.notify(Config.NOTIFICATION_TEMPERATURE_HIGH, notification); }
From source file:com.andrewshu.android.reddit.common.Common.java
public static void newMailNotification(Context context, String mailNotificationStyle, int count) { Intent nIntent = new Intent(context, InboxActivity.class); PendingIntent contentIntent = PendingIntent.getActivity(context, 0, nIntent, 0); Notification notification = new Notification(R.drawable.mail, Constants.HAVE_MAIL_TICKER, System.currentTimeMillis()); if (Constants.PREF_MAIL_NOTIFICATION_STYLE_BIG_ENVELOPE.equals(mailNotificationStyle)) { RemoteViews contentView = new RemoteViews(context.getPackageName(), R.layout.big_envelope_notification); notification.contentView = contentView; } else {//from w ww .j a v a2 s. co m notification.setLatestEventInfo(context, Constants.HAVE_MAIL_TITLE, count + (count == 1 ? " unread message" : " unread messages"), contentIntent); } notification.defaults |= Notification.DEFAULT_SOUND; notification.flags |= Notification.FLAG_ONLY_ALERT_ONCE | Notification.FLAG_AUTO_CANCEL; notification.contentIntent = contentIntent; NotificationManager notificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.notify(Constants.NOTIFICATION_HAVE_MAIL, notification); }
From source file:com.xperia64.timidityae.MusicService.java
public void updateNotification(String title, boolean paused) { //System.out.println("Updating notification"); remoteViews = new RemoteViews(getPackageName(), R.layout.music_notification); remoteViews.setTextViewText(R.id.titley, currTitle); remoteViews.setImageViewResource(R.id.notPause, (paused) ? R.drawable.ic_media_play : R.drawable.ic_media_pause); // Previous/*from w ww .j av a 2s. c o m*/ Intent new_intent = new Intent(); //new_intent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND); new_intent.setAction(getResources().getString(R.string.msrv_rec)); new_intent.putExtra(getResources().getString(R.string.msrv_cmd), 4); PendingIntent pendingNotificationIntent = PendingIntent.getBroadcast(this, 1, new_intent, 0); remoteViews.setOnClickPendingIntent(R.id.notPrev, pendingNotificationIntent); // Play/Pause new_intent = new Intent(); //new_intent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND); new_intent.setAction(getResources().getString(R.string.msrv_rec)); new_intent.putExtra(getResources().getString(R.string.msrv_cmd), 2); pendingNotificationIntent = PendingIntent.getBroadcast(this, 2, new_intent, 0); remoteViews.setOnClickPendingIntent(R.id.notPause, pendingNotificationIntent); // Next new_intent = new Intent(); //new_intent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND); new_intent.setAction(getResources().getString(R.string.msrv_rec)); new_intent.putExtra(getResources().getString(R.string.msrv_cmd), 3); pendingNotificationIntent = PendingIntent.getBroadcast(this, 3, new_intent, 0); remoteViews.setOnClickPendingIntent(R.id.notNext, pendingNotificationIntent); // Stop new_intent = new Intent(); //new_intent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND); new_intent.setAction(getResources().getString(R.string.msrv_rec)); new_intent.putExtra(getResources().getString(R.string.msrv_cmd), 5); pendingNotificationIntent = PendingIntent.getBroadcast(this, 4, new_intent, 0); remoteViews.setOnClickPendingIntent(R.id.notStop, pendingNotificationIntent); final Intent emptyIntent = new Intent(this, TimidityActivity.class); //emptyIntent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND); PendingIntent pendingIntent = PendingIntent.getActivity(this, 5, emptyIntent, PendingIntent.FLAG_UPDATE_CURRENT); NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this) .setContentTitle(getResources().getString(R.string.app_name)).setContentText(currTitle) .setContentIntent(pendingIntent).setContent(remoteViews); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) mBuilder.setSmallIcon(R.drawable.ic_lol); else mBuilder.setSmallIcon(R.drawable.ic_launcher); n = mBuilder.build(); n.flags |= Notification.FLAG_ONLY_ALERT_ONCE | Notification.FLAG_ONGOING_EVENT; if (!foreground) { foreground = true; startForeground(13901858, n); if (!wl.isHeld()) wl.acquire(); TelephonyManager mgr = (TelephonyManager) getSystemService(TELEPHONY_SERVICE); if (mgr != null) { mgr.listen(phoneStateListener, PhoneStateListener.LISTEN_CALL_STATE); } } else { if (!wl.isHeld()) wl.acquire(); NotificationManager mNotificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); mNotificationManager.notify(13901858, n); } if (shouldDoWidget) { Intent intent = new Intent(this, TimidityAEWidgetProvider.class); //Intent intent = new Intent("Ilikepotatoes"); intent.setAction(AppWidgetManager.ACTION_APPWIDGET_UPDATE); // Use an array and EXTRA_APPWIDGET_IDS instead of AppWidgetManager.EXTRA_APPWIDGET_ID, // since it seems the onUpdate() is only fired on that: //intent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND); intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, ids); intent.putExtra("com.xperia64.timidityae.timidityaewidgetprovider.paused", paused); intent.putExtra("com.xperia64.timidityae.timidityaewidgetprovider.title", currTitle); intent.putExtra("com.xperia64.timidityae.timidityaewidgetprovider.onlyart", true); sendBroadcast(intent); } }