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:saphion.fragment.alarm.alert.AlarmAlertReceiver.java
public void newMethod(Context mContext, int pos) { // Instantiate a Builder object. NotificationCompat.Builder builder = new NotificationCompat.Builder(mContext).setSmallIcon(R.drawable.clock) .setContentTitle("Battery Alarm").setContentText("Battery Level is " + level); // Creates an Intent for the Activity Intent notifyIntents = new Intent(mContext, saphion.fragments.alarm.AlarmAlert.class); // Sets the Activity to start in a new, empty task notifyIntents.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); notifyIntents.putExtra(PreferenceHelper.BAT_VALS, pos); notifyIntents.putExtra(PreferenceHelper.CURR_RING, level); // notifyIntents. // Creates the PendingIntent PendingIntent notifyIntent = PendingIntent.getActivity(mContext, 0, notifyIntents, PendingIntent.FLAG_UPDATE_CURRENT); // Puts the PendingIntent into the notification builder builder.setContentIntent(notifyIntent); builder.setFullScreenIntent(notifyIntent, true); // Notifications are issued by sending them to the // NotificationManager system service. NotificationManager mNotificationManager = (NotificationManager) mContext .getSystemService(Context.NOTIFICATION_SERVICE); builder.setPriority(Notification.PRIORITY_HIGH); // Builds an anonymous Notification object from the builder, and // passes it to the NotificationManager // Toast.makeText(mContext, "Recieved", Toast.LENGTH_LONG).show(); mNotificationManager.notify(ID, builder.build()); }
From source file:seantool.SeanNotify.java
public void sentSimpleNotification(int iconResId, String title, String message) { NotificationCompat.Builder builder = new NotificationCompat.Builder(context).setContentTitle(title) .setContentText(message);//from ww w . ja v a 2 s .c om if (iconResId == -1) { builder.setSmallIcon(android.R.drawable.ic_notification_overlay); } else { builder.setSmallIcon(iconResId); } builder.setPriority(Notification.PRIORITY_HIGH); builder.setDefaults(Notification.DEFAULT_ALL); NotificationManager manager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); manager.notify(0, builder.build()); }
From source file:jahirfiquitiva.iconshowcase.services.NotificationsService.java
@SuppressWarnings("ResourceAsColor") private void pushNotification(String content, int type, int ID) { Preferences mPrefs = new Preferences(this); String appName = Utils.getStringFromResources(this, R.string.app_name); String title = appName, notifContent = null; switch (type) { case 1://from w w w .j a va 2 s . co m title = getResources().getString(R.string.new_walls_notif_title, appName); notifContent = getResources().getString(R.string.new_walls_notif_content, content); break; case 2: title = appName + " " + getResources().getString(R.string.news).toLowerCase(); notifContent = content; break; } // Send Notification NotificationManager notifManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); NotificationCompat.Builder notifBuilder = new NotificationCompat.Builder(this); notifBuilder.setAutoCancel(true); notifBuilder.setContentTitle(title); if (notifContent != null) { notifBuilder.setStyle(new NotificationCompat.BigTextStyle().bigText(notifContent)); notifBuilder.setContentText(notifContent); } notifBuilder.setTicker(title); Uri ringtoneUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); notifBuilder.setSound(ringtoneUri); if (mPrefs.getNotifsVibrationEnabled()) { notifBuilder.setVibrate(new long[] { 500, 500 }); } else { notifBuilder.setVibrate(null); } int ledColor = ThemeUtils.darkTheme ? ContextCompat.getColor(this, R.color.dark_theme_accent) : ContextCompat.getColor(this, R.color.light_theme_accent); notifBuilder.setColor(ledColor); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { notifBuilder.setPriority(Notification.PRIORITY_HIGH); } Class appLauncherActivity = getLauncherClass(getApplicationContext()); if (appLauncherActivity != null) { Intent appIntent = new Intent(this, appLauncherActivity); appIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP); appIntent.putExtra("notifType", type); TaskStackBuilder stackBuilder = TaskStackBuilder.create(this); stackBuilder.addParentStack(appLauncherActivity); // Adds the Intent that starts the Activity to the top of the stack stackBuilder.addNextIntent(appIntent); PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); notifBuilder.setContentIntent(resultPendingIntent); } notifBuilder.setOngoing(false); notifBuilder.setSmallIcon(R.drawable.ic_notifications); Notification notif = notifBuilder.build(); if (mPrefs.getNotifsLedEnabled()) { notif.ledARGB = ledColor; } notifManager.notify(ID, notif); }
From source file:org.dmfs.tasks.notification.NotificationActionUtils.java
@TargetApi(Build.VERSION_CODES.JELLY_BEAN) public static void sendStartNotification(Context context, String title, Uri taskUri, int notificationId, long startDate, boolean startAllDay, boolean silent) { String startString = ""; if (startAllDay) { startString = context.getString(R.string.notification_task_start_today); } else {/* www.ja v a 2s . c om*/ startString = context.getString(R.string.notification_task_start_date, formatTime(context, makeTime(startDate, startAllDay))); } NotificationManager notificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); // build notification NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context) .setSmallIcon(R.drawable.ic_notification) .setContentTitle(context.getString(R.string.notification_task_start_title, title)) .setContentText(startString); // 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); } // set notification time // set displayed time if (startAllDay) { 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(startDate); } // add actions if (android.os.Build.VERSION.SDK_INT >= VERSION_CODES.ICE_CREAM_SANDWICH) { NotificationAction completeAction = new NotificationAction(NotificationUpdaterService.ACTION_COMPLETE, R.string.notification_action_completed, notificationId, taskUri, startDate); mBuilder.addAction(NotificationUpdaterService.getCompleteAction(context, NotificationActionUtils.getNotificationActionPendingIntent(context, completeAction))); } // 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); mBuilder.setContentIntent(resultPendingIntent); notificationManager.notify(notificationId, mBuilder.build()); }
From source file:com.android.deskclock.data.TimerNotificationBuilderN.java
@Override public Notification build(Context context, NotificationModel nm, List<Timer> unexpired) { final Timer timer = unexpired.get(0); final int count = unexpired.size(); // Compute some values required below. final boolean running = timer.isRunning(); final Resources res = context.getResources(); final long base = getChronometerBase(timer); final String pname = context.getPackageName(); final RemoteViews content = new RemoteViews(pname, R.layout.chronometer_notif_content); content.setChronometerCountDown(R.id.chronometer, true); content.setChronometer(R.id.chronometer, base, null, running); final List<Notification.Action> actions = new ArrayList<>(2); final CharSequence stateText; if (count == 1) { if (running) { // Single timer is running. if (TextUtils.isEmpty(timer.getLabel())) { stateText = res.getString(R.string.timer_notification_label); } else { stateText = timer.getLabel(); }// w w w . j a va 2s.c o m // Left button: Pause final Intent pause = new Intent(context, TimerService.class) .setAction(HandleDeskClockApiCalls.ACTION_PAUSE_TIMER) .putExtra(HandleDeskClockApiCalls.EXTRA_TIMER_ID, timer.getId()); final Icon icon1 = Icon.createWithResource(context, R.drawable.ic_pause_24dp); final CharSequence title1 = res.getText(R.string.timer_pause); final PendingIntent intent1 = Utils.pendingServiceIntent(context, pause); actions.add(new Notification.Action.Builder(icon1, title1, intent1).build()); // Right Button: +1 Minute final Intent addMinute = new Intent(context, TimerService.class) .setAction(HandleDeskClockApiCalls.ACTION_ADD_MINUTE_TIMER) .putExtra(HandleDeskClockApiCalls.EXTRA_TIMER_ID, timer.getId()); final Icon icon2 = Icon.createWithResource(context, R.drawable.ic_add_24dp); final CharSequence title2 = res.getText(R.string.timer_plus_1_min); final PendingIntent intent2 = Utils.pendingServiceIntent(context, addMinute); actions.add(new Notification.Action.Builder(icon2, title2, intent2).build()); } else { // Single timer is paused. stateText = res.getString(R.string.timer_paused); // Left button: Start final Intent start = new Intent(context, TimerService.class) .setAction(HandleDeskClockApiCalls.ACTION_START_TIMER) .putExtra(HandleDeskClockApiCalls.EXTRA_TIMER_ID, timer.getId()); final Icon icon1 = Icon.createWithResource(context, R.drawable.ic_start_24dp); final CharSequence title1 = res.getText(R.string.sw_resume_button); final PendingIntent intent1 = Utils.pendingServiceIntent(context, start); actions.add(new Notification.Action.Builder(icon1, title1, intent1).build()); // Right Button: Reset final Intent reset = new Intent(context, TimerService.class) .setAction(HandleDeskClockApiCalls.ACTION_RESET_TIMER) .putExtra(HandleDeskClockApiCalls.EXTRA_TIMER_ID, timer.getId()); final Icon icon2 = Icon.createWithResource(context, R.drawable.ic_reset_24dp); final CharSequence title2 = res.getText(R.string.sw_reset_button); final PendingIntent intent2 = Utils.pendingServiceIntent(context, reset); actions.add(new Notification.Action.Builder(icon2, title2, intent2).build()); } } else { if (running) { // At least one timer is running. stateText = res.getString(R.string.timers_in_use, count); } else { // All timers are paused. stateText = res.getString(R.string.timers_stopped, count); } final Intent reset = TimerService.createResetUnexpiredTimersIntent(context); final Icon icon1 = Icon.createWithResource(context, R.drawable.ic_reset_24dp); final CharSequence title1 = res.getText(R.string.timer_reset_all); final PendingIntent intent1 = Utils.pendingServiceIntent(context, reset); actions.add(new Notification.Action.Builder(icon1, title1, intent1).build()); } content.setTextViewText(R.id.state, stateText); // Intent to load the app and show the timer when the notification is tapped. final Intent showApp = new Intent(context, HandleDeskClockApiCalls.class) .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK).setAction(HandleDeskClockApiCalls.ACTION_SHOW_TIMERS) .putExtra(HandleDeskClockApiCalls.EXTRA_TIMER_ID, timer.getId()) .putExtra(HandleDeskClockApiCalls.EXTRA_EVENT_LABEL, R.string.label_notification); final PendingIntent pendingShowApp = PendingIntent.getActivity(context, 0, showApp, PendingIntent.FLAG_ONE_SHOT | PendingIntent.FLAG_UPDATE_CURRENT); return new Notification.Builder(context).setOngoing(true).setLocalOnly(true).setShowWhen(false) .setAutoCancel(false).setCustomContentView(content).setContentIntent(pendingShowApp) .setPriority(Notification.PRIORITY_HIGH).setCategory(Notification.CATEGORY_ALARM) .setSmallIcon(R.drawable.stat_notify_timer).setGroup(nm.getTimerNotificationGroupKey()) .setVisibility(Notification.VISIBILITY_PUBLIC).setStyle(new Notification.DecoratedCustomViewStyle()) .setActions(actions.toArray(new Notification.Action[actions.size()])) .setColor(ContextCompat.getColor(context, R.color.default_background)).build(); }
From source file:com.androidinspain.deskclock.data.TimerNotificationBuilder.java
public Notification build(Context context, NotificationModel nm, List<Timer> unexpired) { final Timer timer = unexpired.get(0); final int count = unexpired.size(); // Compute some values required below. final boolean running = timer.isRunning(); final Resources res = context.getResources(); final long base = getChronometerBase(timer); final String pname = context.getPackageName(); final List<Action> actions = new ArrayList<>(2); final CharSequence stateText; if (count == 1) { if (running) { // Single timer is running. if (TextUtils.isEmpty(timer.getLabel())) { stateText = res.getString(com.androidinspain.deskclock.R.string.timer_notification_label); } else { stateText = timer.getLabel(); }/*from w ww. j a va 2 s .co m*/ // Left button: Pause final Intent pause = new Intent(context, TimerService.class) .setAction(TimerService.ACTION_PAUSE_TIMER) .putExtra(TimerService.EXTRA_TIMER_ID, timer.getId()); @DrawableRes final int icon1 = com.androidinspain.deskclock.R.drawable.ic_pause_24dp; final CharSequence title1 = res.getText(com.androidinspain.deskclock.R.string.timer_pause); final PendingIntent intent1 = Utils.pendingServiceIntent(context, pause); actions.add(new Action.Builder(icon1, title1, intent1).build()); // Right Button: +1 Minute final Intent addMinute = new Intent(context, TimerService.class) .setAction(TimerService.ACTION_ADD_MINUTE_TIMER) .putExtra(TimerService.EXTRA_TIMER_ID, timer.getId()); @DrawableRes final int icon2 = com.androidinspain.deskclock.R.drawable.ic_add_24dp; final CharSequence title2 = res.getText(com.androidinspain.deskclock.R.string.timer_plus_1_min); final PendingIntent intent2 = Utils.pendingServiceIntent(context, addMinute); actions.add(new Action.Builder(icon2, title2, intent2).build()); } else { // Single timer is paused. stateText = res.getString(com.androidinspain.deskclock.R.string.timer_paused); // Left button: Start final Intent start = new Intent(context, TimerService.class) .setAction(TimerService.ACTION_START_TIMER) .putExtra(TimerService.EXTRA_TIMER_ID, timer.getId()); @DrawableRes final int icon1 = com.androidinspain.deskclock.R.drawable.ic_start_24dp; final CharSequence title1 = res.getText(com.androidinspain.deskclock.R.string.sw_resume_button); final PendingIntent intent1 = Utils.pendingServiceIntent(context, start); actions.add(new Action.Builder(icon1, title1, intent1).build()); // Right Button: Reset final Intent reset = new Intent(context, TimerService.class) .setAction(TimerService.ACTION_RESET_TIMER) .putExtra(TimerService.EXTRA_TIMER_ID, timer.getId()); @DrawableRes final int icon2 = com.androidinspain.deskclock.R.drawable.ic_reset_24dp; final CharSequence title2 = res.getText(com.androidinspain.deskclock.R.string.sw_reset_button); final PendingIntent intent2 = Utils.pendingServiceIntent(context, reset); actions.add(new Action.Builder(icon2, title2, intent2).build()); } } else { if (running) { // At least one timer is running. stateText = res.getString(com.androidinspain.deskclock.R.string.timers_in_use, count); } else { // All timers are paused. stateText = res.getString(com.androidinspain.deskclock.R.string.timers_stopped, count); } final Intent reset = TimerService.createResetUnexpiredTimersIntent(context); @DrawableRes final int icon1 = com.androidinspain.deskclock.R.drawable.ic_reset_24dp; final CharSequence title1 = res.getText(com.androidinspain.deskclock.R.string.timer_reset_all); final PendingIntent intent1 = Utils.pendingServiceIntent(context, reset); actions.add(new Action.Builder(icon1, title1, intent1).build()); } // Intent to load the app and show the timer when the notification is tapped. final Intent showApp = new Intent(context, TimerService.class).setAction(TimerService.ACTION_SHOW_TIMER) .putExtra(TimerService.EXTRA_TIMER_ID, timer.getId()) .putExtra(Events.EXTRA_EVENT_LABEL, com.androidinspain.deskclock.R.string.label_notification); final PendingIntent pendingShowApp = PendingIntent.getService(context, REQUEST_CODE_UPCOMING, showApp, PendingIntent.FLAG_ONE_SHOT | PendingIntent.FLAG_UPDATE_CURRENT); final Builder notification = new NotificationCompat.Builder(context).setOngoing(true).setLocalOnly(true) .setShowWhen(false).setAutoCancel(false).setContentIntent(pendingShowApp) .setPriority(Notification.PRIORITY_HIGH).setCategory(NotificationCompat.CATEGORY_ALARM) .setSmallIcon(com.androidinspain.deskclock.R.drawable.stat_notify_timer) .setSortKey(nm.getTimerNotificationSortKey()).setVisibility(NotificationCompat.VISIBILITY_PUBLIC) .setStyle(new NotificationCompat.DecoratedCustomViewStyle()) .setColor(ContextCompat.getColor(context, com.androidinspain.deskclock.R.color.default_background)); for (Action action : actions) { notification.addAction(action); } if (Utils.isNOrLater()) { notification.setCustomContentView(buildChronometer(pname, base, running, stateText)) .setGroup(nm.getTimerNotificationGroupKey()); } else { final CharSequence contentTextPreN; if (count == 1) { contentTextPreN = TimerStringFormatter.formatTimeRemaining(context, timer.getRemainingTime(), false); } else if (running) { final String timeRemaining = TimerStringFormatter.formatTimeRemaining(context, timer.getRemainingTime(), false); contentTextPreN = context.getString(com.androidinspain.deskclock.R.string.next_timer_notif, timeRemaining); } else { contentTextPreN = context.getString(com.androidinspain.deskclock.R.string.all_timers_stopped_notif); } notification.setContentTitle(stateText).setContentText(contentTextPreN); final AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); final Intent updateNotification = TimerService.createUpdateNotificationIntent(context); final long remainingTime = timer.getRemainingTime(); if (timer.isRunning() && remainingTime > MINUTE_IN_MILLIS) { // Schedule a callback to update the time-sensitive information of the running timer final PendingIntent pi = PendingIntent.getService(context, REQUEST_CODE_UPCOMING, updateNotification, PendingIntent.FLAG_ONE_SHOT | PendingIntent.FLAG_UPDATE_CURRENT); final long nextMinuteChange = remainingTime % MINUTE_IN_MILLIS; final long triggerTime = SystemClock.elapsedRealtime() + nextMinuteChange; TimerModel.schedulePendingIntent(am, triggerTime, pi); } else { // Cancel the update notification callback. final PendingIntent pi = PendingIntent.getService(context, 0, updateNotification, PendingIntent.FLAG_ONE_SHOT | PendingIntent.FLAG_NO_CREATE); if (pi != null) { am.cancel(pi); pi.cancel(); } } } return notification.build(); }
From source file:com.example.android.wearable.wear.wearnotifications.handlers.BigTextIntentService.java
private NotificationCompat.Builder recreateBuilderWithBigTextStyle() { // Main steps for building a BIG_TEXT_STYLE notification (for more detailed comments on // building this notification, check StandaloneMainActivity.java):: // 0. Get your data // 1. Build the BIG_TEXT_STYLE // 2. Set up main Intent for notification // 3. Create additional Actions for the Notification // 4. Build and issue the notification // 0. Get your data (everything unique per Notification) MockDatabase.BigTextStyleReminderAppData bigTextStyleReminderAppData = MockDatabase.getBigTextStyleData(); // 1. Build the BIG_TEXT_STYLE BigTextStyle bigTextStyle = new NotificationCompat.BigTextStyle() .bigText(bigTextStyleReminderAppData.getBigText()) .setBigContentTitle(bigTextStyleReminderAppData.getBigContentTitle()) .setSummaryText(bigTextStyleReminderAppData.getSummaryText()); // 2. Set up main Intent for notification Intent mainIntent = new Intent(this, BigTextMainActivity.class); PendingIntent mainPendingIntent = PendingIntent.getActivity(this, 0, mainIntent, PendingIntent.FLAG_UPDATE_CURRENT); // 3. Create additional Actions (Intents) for the Notification // Snooze Action Intent snoozeIntent = new Intent(this, BigTextIntentService.class); snoozeIntent.setAction(BigTextIntentService.ACTION_SNOOZE); PendingIntent snoozePendingIntent = PendingIntent.getService(this, 0, snoozeIntent, 0); NotificationCompat.Action snoozeAction = new NotificationCompat.Action.Builder( R.drawable.ic_alarm_white_48dp, "Snooze", snoozePendingIntent).build(); // Dismiss Action Intent dismissIntent = new Intent(this, BigTextIntentService.class); dismissIntent.setAction(BigTextIntentService.ACTION_DISMISS); PendingIntent dismissPendingIntent = PendingIntent.getService(this, 0, dismissIntent, 0); NotificationCompat.Action dismissAction = new NotificationCompat.Action.Builder( R.drawable.ic_cancel_white_48dp, "Dismiss", dismissPendingIntent).build(); // 4. Build and issue the notification NotificationCompat.Builder notificationCompatBuilder = new NotificationCompat.Builder( getApplicationContext());// ww w .ja v a2s . c o m GlobalNotificationBuilder.setNotificationCompatBuilderInstance(notificationCompatBuilder); notificationCompatBuilder.setStyle(bigTextStyle) .setContentTitle(bigTextStyleReminderAppData.getContentTitle()) .setContentText(bigTextStyleReminderAppData.getContentText()).setSmallIcon(R.drawable.ic_launcher) .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.ic_alarm_white_48dp)) .setColor(getResources().getColor(R.color.colorPrimary)).setCategory(Notification.CATEGORY_REMINDER) .setPriority(Notification.PRIORITY_HIGH).setVisibility(Notification.VISIBILITY_PUBLIC) .addAction(snoozeAction).addAction(dismissAction); /* REPLICATE_NOTIFICATION_STYLE_CODE: * You can replicate Notification Style functionality on Wear 2.0 (24+) by not setting the * main content intent, that is, skipping the call setContentIntent(). However, you need to * still allow the user to open the native Wear app from the Notification itself, so you * add an action to launch the app. */ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { // Enables launching app in Wear 2.0 while keeping the old Notification Style behavior. NotificationCompat.Action mainAction = new NotificationCompat.Action.Builder(R.drawable.ic_launcher, "Open", mainPendingIntent).build(); notificationCompatBuilder.addAction(mainAction); } else { // Wear 1.+ still functions the same, so we set the main content intent. notificationCompatBuilder.setContentIntent(mainPendingIntent); } return notificationCompatBuilder; }
From source file:io.coldstart.android.GCMIntentService.java
private void sendBatchNotification(String batchCount) { if (null == batchCount) batchCount = "1+"; Intent intent = new Intent(this, TrapListActivity.class); intent.putExtra("forceDownload", true); PendingIntent pIntent = PendingIntent.getActivity(this, 0, intent, 0); Intent broadcastDownload = new Intent(); broadcastDownload.setAction(BatchDownloadReceiver.BROADCAST_ACTION); PendingIntent pBroadcastDownload = PendingIntent.getBroadcast(this, 0, broadcastDownload, 0); Intent broadcastIgnore = new Intent(); broadcastIgnore.setAction(BatchIgnoreReceiver.BROADCAST_ACTION); PendingIntent pBroadcastIgnore = PendingIntent.getBroadcast(this, 0, broadcastIgnore, 0); Uri uri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); Notification notification = null; if (Build.VERSION.SDK_INT >= 16) { notification = new Notification.InboxStyle( new Notification.Builder(this).setContentTitle("A batch of Traps has been sent") .setContentText("\"Batched traps are waiting to be downloaded") .setSmallIcon(R.drawable.ic_stat_ratelimit).setVibrate(new long[] { 0, 100, 200, 300 }) .setAutoCancel(true).setSound(uri).setPriority(Notification.PRIORITY_HIGH) .setTicker("A batch of Traps has been sent") .addAction(R.drawable.ic_download_batch, "Get Batched Traps", pBroadcastDownload) .addAction(R.drawable.ic_ignore, "Ignore Batch", pBroadcastIgnore)) .setBigContentTitle("A batch of Traps has been sent") .setSummaryText("Launch ColdStart.io to Manage These Events") .addLine("A number of traps have been sent and batched for delivery") .addLine("The current number of items queued is " + batchCount).addLine(" ") .addLine("Tap \"Get Batched Traps\" to download the cached traps") .addLine("Tap \"Ignore Batch\" to delete them from the server.") .build(); } else {// w ww .j av a2 s .c o m notification = new Notification.Builder(this).setContentTitle("A batch of Traps has been sent") .setContentText( "A number of traps have been sent and batched for delivery. The current number of items queued is " + batchCount + "\nTap \"Get Alerts\" to batch download the outstanding traps or tap \"Ignore\" to delete them from the server.") .setSmallIcon(R.drawable.ic_stat_ratelimit).setContentIntent(pIntent) .setVibrate(new long[] { 0, 100, 200, 300 }).setAutoCancel(true).setSound(uri).build(); } NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); notificationManager.notify(43524, notification); }
From source file:org.chromium.chrome.browser.media.MediaCaptureNotificationService.java
/** * Creates a notification for the provided notificationId and mediaType. * @param notificationId Unique id of the notification. * @param mediaType Media type of the notification. * @param url Url of the current webrtc call. *///w w w. j ava 2 s .com private void createNotification(int notificationId, int mediaType, String url) { NotificationCompat.Builder builder = new NotificationCompat.Builder(mContext).setAutoCancel(false) .setOngoing(true).setContentTitle(mContext.getString(R.string.app_name)) .setSmallIcon(getNotificationIconId(mediaType)).setLocalOnly(true); StringBuilder contentText = new StringBuilder(getNotificationContentText(mediaType, url)).append('.'); Intent tabIntent = Tab.createBringTabToFrontIntent(notificationId); if (tabIntent != null) { PendingIntent contentIntent = PendingIntent.getActivity(mContext, notificationId, tabIntent, 0); builder.setContentIntent(contentIntent); if (mediaType == MEDIATYPE_SCREEN_CAPTURE) { // Add a "Stop" button to the screen capture notification and turn the notification // into a high priority one. builder.setPriority(Notification.PRIORITY_HIGH); builder.setVibrate(new long[0]); builder.addAction(R.drawable.ic_vidcontrol_stop, mContext.getResources().getString(R.string.accessibility_stop), buildStopCapturePendingIntent(notificationId)); } else { contentText.append(mContext.getResources().getString(R.string.media_notification_link_text, url)); } } else { contentText.append(" ").append(url); } builder.setContentText(contentText); Notification notification = new NotificationCompat.BigTextStyle(builder).bigText(contentText).build(); mNotificationManager.notify(NOTIFICATION_NAMESPACE, notificationId, notification); mNotifications.put(notificationId, mediaType); updateSharedPreferencesEntry(notificationId, false); }
From source file:com.wizardsofm.deskclock.data.TimerNotificationBuilderN.java
@Override public Notification build(Context context, NotificationModel nm, List<Timer> unexpired) { final Timer timer = unexpired.get(0); final int count = unexpired.size(); // Compute some values required below. final boolean running = timer.isRunning(); final Resources res = context.getResources(); final long base = getChronometerBase(timer); final String pname = context.getPackageName(); final RemoteViews content = new RemoteViews(pname, com.wizardsofm.deskclock.R.layout.chronometer_notif_content); content.setChronometerCountDown(com.wizardsofm.deskclock.R.id.chronometer, true); content.setChronometer(com.wizardsofm.deskclock.R.id.chronometer, base, null, running); final List<Notification.Action> actions = new ArrayList<>(2); final CharSequence stateText; if (count == 1) { if (running) { // Single timer is running. if (TextUtils.isEmpty(timer.getLabel())) { stateText = res.getString(com.wizardsofm.deskclock.R.string.timer_notification_label); } else { stateText = timer.getLabel(); }//from w ww. j a va 2 s . c o m // Left button: Pause final Intent pause = new Intent(context, TimerService.class) .setAction(HandleDeskClockApiCalls.ACTION_PAUSE_TIMER) .putExtra(HandleDeskClockApiCalls.EXTRA_TIMER_ID, timer.getId()); final Icon icon1 = Icon.createWithResource(context, com.wizardsofm.deskclock.R.drawable.ic_pause_24dp); final CharSequence title1 = res.getText(com.wizardsofm.deskclock.R.string.timer_pause); final PendingIntent intent1 = Utils.pendingServiceIntent(context, pause); actions.add(new Notification.Action.Builder(icon1, title1, intent1).build()); // Right Button: +1 Minute final Intent addMinute = new Intent(context, TimerService.class) .setAction(HandleDeskClockApiCalls.ACTION_ADD_MINUTE_TIMER) .putExtra(HandleDeskClockApiCalls.EXTRA_TIMER_ID, timer.getId()); final Icon icon2 = Icon.createWithResource(context, com.wizardsofm.deskclock.R.drawable.ic_add_24dp); final CharSequence title2 = res.getText(com.wizardsofm.deskclock.R.string.timer_plus_1_min); final PendingIntent intent2 = Utils.pendingServiceIntent(context, addMinute); actions.add(new Notification.Action.Builder(icon2, title2, intent2).build()); } else { // Single timer is paused. stateText = res.getString(com.wizardsofm.deskclock.R.string.timer_paused); // Left button: Start final Intent start = new Intent(context, TimerService.class) .setAction(HandleDeskClockApiCalls.ACTION_START_TIMER) .putExtra(HandleDeskClockApiCalls.EXTRA_TIMER_ID, timer.getId()); final Icon icon1 = Icon.createWithResource(context, com.wizardsofm.deskclock.R.drawable.ic_start_24dp); final CharSequence title1 = res.getText(com.wizardsofm.deskclock.R.string.sw_resume_button); final PendingIntent intent1 = Utils.pendingServiceIntent(context, start); actions.add(new Notification.Action.Builder(icon1, title1, intent1).build()); // Right Button: Reset final Intent reset = new Intent(context, TimerService.class) .setAction(HandleDeskClockApiCalls.ACTION_RESET_TIMER) .putExtra(HandleDeskClockApiCalls.EXTRA_TIMER_ID, timer.getId()); final Icon icon2 = Icon.createWithResource(context, com.wizardsofm.deskclock.R.drawable.ic_reset_24dp); final CharSequence title2 = res.getText(com.wizardsofm.deskclock.R.string.sw_reset_button); final PendingIntent intent2 = Utils.pendingServiceIntent(context, reset); actions.add(new Notification.Action.Builder(icon2, title2, intent2).build()); } } else { if (running) { // At least one timer is running. stateText = res.getString(com.wizardsofm.deskclock.R.string.timers_in_use, count); } else { // All timers are paused. stateText = res.getString(com.wizardsofm.deskclock.R.string.timers_stopped, count); } final Intent reset = TimerService.createResetUnexpiredTimersIntent(context); final Icon icon1 = Icon.createWithResource(context, com.wizardsofm.deskclock.R.drawable.ic_reset_24dp); final CharSequence title1 = res.getText(com.wizardsofm.deskclock.R.string.timer_reset_all); final PendingIntent intent1 = Utils.pendingServiceIntent(context, reset); actions.add(new Notification.Action.Builder(icon1, title1, intent1).build()); } content.setTextViewText(com.wizardsofm.deskclock.R.id.state, stateText); // Intent to load the app and show the timer when the notification is tapped. final Intent showApp = new Intent(context, HandleDeskClockApiCalls.class) .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK).setAction(HandleDeskClockApiCalls.ACTION_SHOW_TIMERS) .putExtra(HandleDeskClockApiCalls.EXTRA_TIMER_ID, timer.getId()) .putExtra(HandleDeskClockApiCalls.EXTRA_EVENT_LABEL, com.wizardsofm.deskclock.R.string.label_notification); final PendingIntent pendingShowApp = PendingIntent.getActivity(context, 0, showApp, PendingIntent.FLAG_ONE_SHOT | PendingIntent.FLAG_UPDATE_CURRENT); return new Notification.Builder(context).setOngoing(true).setLocalOnly(true).setShowWhen(false) .setAutoCancel(false).setCustomContentView(content).setContentIntent(pendingShowApp) .setPriority(Notification.PRIORITY_HIGH).setCategory(Notification.CATEGORY_ALARM) .setSmallIcon(com.wizardsofm.deskclock.R.drawable.stat_notify_timer) .setGroup(nm.getTimerNotificationGroupKey()).setVisibility(Notification.VISIBILITY_PUBLIC) .setStyle(new Notification.DecoratedCustomViewStyle()) .setActions(actions.toArray(new Notification.Action[actions.size()])) .setColor(ContextCompat.getColor(context, com.wizardsofm.deskclock.R.color.default_background)) .build(); }