List of usage examples for android.app Notification PRIORITY_HIGH
int PRIORITY_HIGH
To view the source code for android.app Notification PRIORITY_HIGH.
Click Source Link
From source file:github.daneren2005.dsub.util.Notifications.java
public static void showPlayingNotification(final Context context, final DownloadService downloadService, final Handler handler, MusicDirectory.Entry song) { // Set the icon, scrolling text and timestamp final Notification notification = new Notification(R.drawable.stat_notify_playing, song.getTitle(), System.currentTimeMillis()); final boolean playing = downloadService.getPlayerState() == PlayerState.STARTED; if (playing) { notification.flags |= Notification.FLAG_NO_CLEAR | Notification.FLAG_ONGOING_EVENT; }//from w ww.j a va 2 s . co m boolean remote = downloadService.isRemoteEnabled(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { RemoteViews expandedContentView = new RemoteViews(context.getPackageName(), R.layout.notification_expanded); setupViews(expandedContentView, context, song, true, playing, remote); notification.bigContentView = expandedContentView; notification.priority = Notification.PRIORITY_HIGH; } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { notification.visibility = Notification.VISIBILITY_PUBLIC; } RemoteViews smallContentView = new RemoteViews(context.getPackageName(), R.layout.notification); setupViews(smallContentView, context, song, false, playing, remote); notification.contentView = smallContentView; Intent notificationIntent = new Intent(context, SubsonicFragmentActivity.class); notificationIntent.putExtra(Constants.INTENT_EXTRA_NAME_DOWNLOAD, true); notificationIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP); notification.contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, 0); playShowing = true; if (downloadForeground && downloadShowing) { downloadForeground = false; handler.post(new Runnable() { @Override public void run() { downloadService.stopForeground(true); showDownloadingNotification(context, downloadService, handler, downloadService.getCurrentDownloading(), downloadService.getBackgroundDownloads().size()); downloadService.startForeground(NOTIFICATION_ID_PLAYING, notification); } }); } else { handler.post(new Runnable() { @Override public void run() { if (playing) { downloadService.startForeground(NOTIFICATION_ID_PLAYING, notification); } else { playShowing = false; persistentPlayingShowing = true; NotificationManager notificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); downloadService.stopForeground(false); notificationManager.notify(NOTIFICATION_ID_PLAYING, notification); } } }); } // Update widget DSubWidgetProvider.notifyInstances(context, downloadService, playing); }
From source file:com.achep.acdisplay.notifications.NotificationHelper.java
@NonNull public static Notification buildNotification(@NonNull Context context, final int id, @NonNull Object... objects) { final Resources res = context.getResources(); final NotificationCompat.Builder builder = new NotificationCompat.Builder(context) .setSmallIcon(R.drawable.stat_acdisplay).setColor(App.ACCENT_COLOR).setAutoCancel(true); PendingIntent pi = null;/*from ww w . j a v a 2 s. c o m*/ switch (id) { case App.ID_NOTIFY_TEST: { NotificationCompat.BigTextStyle bts = new NotificationCompat.BigTextStyle() .bigText(res.getString(R.string.notification_test_message_large)); builder.setStyle(bts).setContentTitle(res.getString(R.string.app_name)) .setContentText(res.getString(R.string.notification_test_message)) .setLargeIcon(BitmapFactory.decodeResource(res, R.mipmap.ic_launcher)) .setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)); break; } case App.ID_NOTIFY_BATH: { CharSequence contentText = (CharSequence) objects[0]; Intent contentIntent = (Intent) objects[1]; // Build notification pi = PendingIntent.getActivity(context, id, contentIntent, PendingIntent.FLAG_UPDATE_CURRENT); builder.setContentTitle(res.getString(R.string.service_bath)).setContentText(contentText) .setPriority(Notification.PRIORITY_MIN); break; } case App.ID_NOTIFY_INIT: { builder.setSmallIcon(R.drawable.stat_notify).setContentTitle(res.getString(R.string.app_name)) .setContentText(res.getString(R.string.notification_init_text)) .setPriority(Notification.PRIORITY_MIN); break; } case App.ID_NOTIFY_APP_AUTO_DISABLED: { CharSequence summary = (CharSequence) objects[0]; NotificationCompat.BigTextStyle bts = new NotificationCompat.BigTextStyle() .bigText(res.getString(R.string.permissions_auto_disabled)).setSummaryText(summary); builder.setLargeIcon(BitmapFactory.decodeResource(res, R.mipmap.ic_launcher)) .setContentTitle(res.getString(R.string.app_name)) .setContentText(res.getString(R.string.permissions_auto_disabled)) .setPriority(Notification.PRIORITY_HIGH).setStyle(bts); break; } default: throw new IllegalArgumentException(); } if (pi == null) { pi = PendingIntent.getActivity(context, id, new Intent(context, MainActivity.class), PendingIntent.FLAG_UPDATE_CURRENT); } return builder.setContentIntent(pi).build(); }
From source file:com.luan.thermospy.android.core.NotificationHandler.java
private NotificationCompat.Builder createBuilder(Context c, String temperature, boolean playSound) { String text = "Current temperature is " + temperature; NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(c) .setPriority(Notification.PRIORITY_HIGH).setAutoCancel(true).setContentTitle("Thermospy") .setContentText(text).setOnlyAlertOnce(false) .setSmallIcon(R.drawable.ic_stat_action_assignment_late); Uri alarmSound = null;/* ww w .ja va 2s. c om*/ if (playSound) { alarmSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_ALARM); } mBuilder.setSound(alarmSound); Intent resultIntent = new Intent(c, MainActivity.class); TaskStackBuilder stackBuilder = TaskStackBuilder.create(c); stackBuilder.addParentStack(MainActivity.class); stackBuilder.addNextIntent(resultIntent); PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); mBuilder.setContentIntent(resultPendingIntent); return mBuilder; }
From source file:com.example.kyle.weatherforecast.MainActivity.java
private void postAlert(int i) { NotificationCompat.Builder builder = new NotificationCompat.Builder(this); builder.setContentTitle("Weather Alert!").setContentText(WeatherData.outlookArray[i]) .setSmallIcon(R.drawable.small_icon) .setLargeIcon(BitmapFactory.decodeResource(getResources(), WeatherData.symbolArray[i])) .setAutoCancel(true).setTicker("Wrap up warm!") // Heads-up and lock screen notifications .setVisibility(Notification.VISIBILITY_PUBLIC).setPriority(Notification.PRIORITY_HIGH) .setVibrate(new long[] { 100, 100, 100, 200, 200 }).setVibrate(new long[] { 0 }) .setCategory(Notification.CATEGORY_ALARM); NotificationCompat.BigPictureStyle bigStyle = new NotificationCompat.BigPictureStyle(); bigStyle.bigPicture(BitmapFactory.decodeResource(getResources(), R.drawable.snow_scene)); builder.setStyle(bigStyle);// w w w . ja v a2 s . co m Intent intent = new Intent(this, MainActivity.class); TaskStackBuilder stackBuilder = TaskStackBuilder.create(this); stackBuilder.addParentStack(MainActivity.class).addNextIntent(intent); PendingIntent pendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); builder.setContentIntent(pendingIntent); NotificationManager notificationManager = (NotificationManager) this .getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.notify(notificationId, builder.build()); notificationId++; Log.d(DEBUG_TAG, "ID: " + notificationId); }
From source file:rtdc.android.AndroidNotificationController.java
public static void addTextMessageNotification(Message message) { String shortMessage = message.getContent().length() < 20 ? message.getContent() : message.getContent().substring(0, 20) + "..."; Context context = AndroidBootstrapper.getAppContext(); NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context) .setSmallIcon(R.drawable.ic_chat_white_24dp) .setContentTitle(ResBundle.get().messageFrom( message.getReceiver().getFirstName() + " " + message.getReceiver().getLastName())) .setContentText(shortMessage); Intent intent = new Intent(context, MainActivity.class); intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP); intent.putExtra("fragment", FragmentType.MESSAGES); PendingIntent inCallPendingIntent = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); mBuilder.setContentIntent(inCallPendingIntent); mBuilder.setVibrate(new long[] { 0, 1000 }); mBuilder.setPriority(Notification.PRIORITY_HIGH); mBuilder.setAutoCancel(true);/*from w ww . jav a 2 s .c o m*/ ((NotificationManager) context.getSystemService(context.NOTIFICATION_SERVICE)) .notify(TEXT_MESSAGE_NOTIFICATION_ID, mBuilder.build()); }
From source file:com.irateam.vkplayer.notifications.PlayerNotificationFactory.java
public PlayerNotificationFactory(Context context) { this.context = context; notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); playerPreviousAction = new Action.Builder(R.drawable.ic_notification_prev_white_24dp, context.getString(R.string.notification_previous), createPendingIntent(PlayerService.PREVIOUS)) .build();//from w w w . ja v a2 s . c o m playerNextAction = new Action.Builder(R.drawable.ic_notification_next_white_24dp, context.getString(R.string.notification_next), createPendingIntent(PlayerService.NEXT)).build(); playerPlayAction = new Action.Builder(R.drawable.ic_notification_play_white_24dp, context.getString(R.string.notification_resume), createPendingIntent(PlayerService.RESUME)).build(); playerPauseAction = new Action.Builder(R.drawable.ic_notification_pause_white_24dp, context.getString(R.string.notification_pause), createPendingIntent(PlayerService.PAUSE)).build(); style = new NotificationCompat.MediaStyle().setShowCancelButton(true) .setCancelButtonIntent(createPendingIntent(PlayerService.STOP)).setShowActionsInCompactView(1, 2); Intent contentIntent = new Intent(context, AudioActivity.class); contentIntent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP); builder = new NotificationCompat.Builder(context); builder.setStyle(style).setPriority(Notification.PRIORITY_HIGH).setWhen(0) .setContentIntent(PendingIntent.getActivity(context, 0, contentIntent, 0)).setAutoCancel(true) .addAction(playerPreviousAction).addAction(playerPlayAction).addAction(playerNextAction); }
From source file:org.linphone.compatibility.ApiTwentyOnePlus.java
public static Notification createSimpleNotification(Context context, String title, String text, PendingIntent intent) {//from www. j a va 2 s .c o m Notification notif = new NotificationCompat.Builder(context).setContentTitle(title).setContentText(text) .setSmallIcon(R.drawable.logo_linphone_57x57).setAutoCancel(true).setContentIntent(intent) .setDefaults(Notification.DEFAULT_ALL).setCategory(Notification.CATEGORY_MESSAGE) .setVisibility(Notification.VISIBILITY_PRIVATE).setPriority(Notification.PRIORITY_HIGH).build(); return notif; }
From source file:github.popeen.dsub.util.Notifications.java
public static void showPlayingNotification(final Context context, final DownloadService downloadService, final Handler handler, MusicDirectory.Entry song) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { getPlayingNotificationChannel(context); }//from www.j a v a 2 s . c o m // Set the icon, scrolling text and timestamp final Notification notification = new NotificationCompat.Builder(context) .setSmallIcon(R.drawable.stat_notify_playing).setTicker(song.getTitle()) .setWhen(System.currentTimeMillis()).setChannelId("now-playing-channel").build(); final boolean playing = downloadService.getPlayerState() == PlayerState.STARTED; if (playing) { notification.flags |= Notification.FLAG_NO_CLEAR | Notification.FLAG_ONGOING_EVENT; } boolean remote = downloadService.isRemoteEnabled(); boolean isSingle = downloadService.isCurrentPlayingSingle(); boolean shouldFastForward = true; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { RemoteViews expandedContentView = new RemoteViews(context.getPackageName(), R.layout.notification_expanded); setupViews(expandedContentView, context, song, true, playing, remote, isSingle, shouldFastForward); notification.bigContentView = expandedContentView; notification.priority = Notification.PRIORITY_HIGH; } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { notification.visibility = Notification.VISIBILITY_PUBLIC; if (Util.getPreferences(context).getBoolean(Constants.PREFERENCES_KEY_HEADS_UP_NOTIFICATION, false) && !UpdateView.hasActiveActivity()) { notification.vibrate = new long[0]; } } RemoteViews smallContentView = new RemoteViews(context.getPackageName(), R.layout.notification); setupViews(smallContentView, context, song, false, playing, remote, isSingle, shouldFastForward); notification.contentView = smallContentView; Intent notificationIntent = new Intent(context, SubsonicFragmentActivity.class); notificationIntent.putExtra(Constants.INTENT_EXTRA_NAME_DOWNLOAD, true); notificationIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); notification.contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, 0); playShowing = true; if (downloadForeground && downloadShowing) { downloadForeground = false; handler.post(new Runnable() { @Override public void run() { stopForeground(downloadService, true); showDownloadingNotification(context, downloadService, handler, downloadService.getCurrentDownloading(), downloadService.getBackgroundDownloads().size()); try { startForeground(downloadService, NOTIFICATION_ID_PLAYING, notification); } catch (Exception e) { Log.e(TAG, "Failed to start notifications after stopping foreground download"); } } }); } else { handler.post(new Runnable() { @Override public void run() { if (playing) { try { startForeground(downloadService, NOTIFICATION_ID_PLAYING, notification); } catch (Exception e) { Log.e(TAG, "Failed to start notifications while playing"); } } else { playShowing = false; persistentPlayingShowing = true; NotificationManager notificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); stopForeground(downloadService, false); try { notificationManager.notify(NOTIFICATION_ID_PLAYING, notification); } catch (Exception e) { Log.e(TAG, "Failed to start notifications while paused"); } } } }); } // Update widget DSubWidgetProvider.notifyInstances(context, downloadService, playing); }
From source file:com.example.mego.adas.utils.NotificationUtils.java
/** * Helper Method to create and display waring notification * * @param context/* w w w .ja va2s . c o m*/ * @param notificationBody the content text with in notification */ public static void showWarningNotification(Context context, String notificationBody) { NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(context) .setColor(ContextCompat.getColor(context, R.color.colorPrimary)).setSmallIcon(R.mipmap.ic_launcher) .setLargeIcon(largeIcon(context)).setContentTitle(context.getString(R.string.notification_waring)) .setContentText(notificationBody) .setStyle(new NotificationCompat.BigTextStyle().bigText(notificationBody)) .setDefaults(Notification.DEFAULT_VIBRATE).setDefaults(Notification.DEFAULT_SOUND) .setContentIntent(contentIntent(context)).setAutoCancel(true); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { notificationBuilder.setPriority(Notification.PRIORITY_HIGH); } NotificationManager notificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.notify(ADAS_WARNING_NOTIFICATION_ID, notificationBuilder.build()); }
From source file:org.dmfs.tasks.notification.NotificationActionUtils.java
@TargetApi(Build.VERSION_CODES.JELLY_BEAN) public static void sendDueAlarmNotification(Context context, String title, Uri taskUri, int notificationId, long dueDate, boolean dueAllDay, String timezone, boolean silent) { NotificationManager notificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); String dueString = ""; if (dueAllDay) { dueString = context.getString(R.string.notification_task_due_today); } else {//from www . j a va 2 s.c o m dueString = context.getString(R.string.notification_task_due_date, formatTime(context, makeTime(dueDate, dueAllDay))); } // build notification NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context) .setSmallIcon(R.drawable.ic_notification) .setContentTitle(context.getString(R.string.notification_task_due_title, title)) .setContentText(dueString); // color mBuilder.setColor(context.getResources().getColor(R.color.colorPrimary)); // dismisses the notification on click mBuilder.setAutoCancel(true); // set high priority to display heads-up notification if (VERSION.SDK_INT >= VERSION_CODES.JELLY_BEAN) { mBuilder.setPriority(Notification.PRIORITY_HIGH); } // set status bar test mBuilder.setTicker(title); // enable light, sound and vibration if (silent) { mBuilder.setDefaults(0); } else { mBuilder.setDefaults(Notification.DEFAULT_ALL); } // Creates an explicit intent for an Activity in your app Intent resultIntent = new Intent(Intent.ACTION_VIEW); resultIntent.setData(taskUri); // 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 Intent that starts the Activity to the top of the stack stackBuilder.addNextIntent(resultIntent); PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); // add actions if (android.os.Build.VERSION.SDK_INT >= VERSION_CODES.ICE_CREAM_SANDWICH) { // delay action mBuilder.addAction(NotificationUpdaterService.getDelay1dAction(context, notificationId, taskUri, dueDate, timezone, dueAllDay)); // complete action NotificationAction completeAction = new NotificationAction(NotificationUpdaterService.ACTION_COMPLETE, R.string.notification_action_completed, notificationId, taskUri, dueDate); mBuilder.addAction(NotificationUpdaterService.getCompleteAction(context, NotificationActionUtils.getNotificationActionPendingIntent(context, completeAction))); } // set displayed time if (dueAllDay) { Time now = new Time(); now.setToNow(); now.set(0, 0, 0, now.monthDay, now.month, now.year); mBuilder.setWhen(now.toMillis(true)); } else { mBuilder.setWhen(dueDate); } mBuilder.setContentIntent(resultPendingIntent); notificationManager.notify(notificationId, mBuilder.build()); }