List of usage examples for android.support.v4.app NotificationManagerCompat from
public static NotificationManagerCompat from(Context context)
From source file:com.sleekcoder.weardemo.NotificationActivity.java
private void buildLocalOnlyNotification(String title, String content, int notificationId, boolean withDismissal) { NotificationCompat.Builder builder = new NotificationCompat.Builder(this); builder.setContentTitle(title).setContentText(content).setLocalOnly(true) .setSmallIcon(R.drawable.ic_launcher); if (withDismissal) { Intent dismissIntent = new Intent(Constants.ACTION_DISMISS); dismissIntent.putExtra(Constants.KEY_NOTIFICATION_ID, Constants.BOTH_ID); PendingIntent pendingIntent = PendingIntent.getService(this, 0, dismissIntent, PendingIntent.FLAG_UPDATE_CURRENT); builder.setDeleteIntent(pendingIntent); }/* ww w . j av a 2s . c o m*/ NotificationManagerCompat.from(this).notify(notificationId, builder.build()); }
From source file:com.actinarium.nagbox.service.NotificationHelper.java
private static void fireForSingleTask(Context context, Task task) { long currentTime = System.currentTimeMillis(); // Notification action to stop the task Intent stopAction = new Intent(context, NagboxService.class); stopAction.setAction(NagboxService.ACTION_ON_NOTIFICATION_ACTION_STOP_TASK); stopAction.putExtra(NagboxService.EXTRA_TASK_ID, task.id); stopAction.putExtra(NagboxService.EXTRA_CANCEL_NOTIFICATION_ID, NAG_NOTIFICATION_ID); PendingIntent stopActionPI = PendingIntent.getService(context, 0, stopAction, PendingIntent.FLAG_UPDATE_CURRENT); // Create public notification Notification publicNotification = makeCommonBuilder(context, currentTime, task.id) .setContentTitle(context.getString(R.string.app_name)) .setContentText(//from w w w. ja v a 2s. c om context.getResources().getQuantityString(R.plurals.notification_stacked_header, 1, 1)) .build(); // Create private notification Notification privateNotification = makeCommonBuilder(context, currentTime, task.id) .setPublicVersion(publicNotification).setContentTitle(task.title) .setContentText(DateUtils.prettyPrintNagDuration(context, task.lastStartedAt, currentTime)) .addAction(R.drawable.ic_cancel, context.getString(R.string.notification_action_stop), stopActionPI) .build(); // Fire! NotificationManagerCompat.from(context).notify(NAG_NOTIFICATION_ID, privateNotification); }
From source file:com.ayuget.redface.job.PrivateMessagesService.java
@TargetApi(android.os.Build.VERSION_CODES.KITKAT) @Override/* w w w . jav a 2 s. c om*/ protected void onHandleIntent(Intent intent) { Log.d(LOG_TAG, "Handling intent"); if (!settings.arePrivateMessagesNoticationsEnabled()) { return; } final NotificationManagerCompat notificationManager = NotificationManagerCompat .from(getApplicationContext()); for (User redfaceUser : userManager.getRealUsers()) { subscriptions.add(mdService.getNewPrivateMessages(redfaceUser) .subscribe(new EndlessObserver<List<PrivateMessage>>() { @Override public void onNext(List<PrivateMessage> privateMessages) { for (PrivateMessage privateMessage : privateMessages) { // Prepare intent to deal with clicks Intent resultIntent = new Intent(PrivateMessagesService.this, PrivateMessagesActivity.class); resultIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); resultIntent.putExtra(UIConstants.ARG_SELECTED_PM, privateMessage); PendingIntent resultPendingIntent = PendingIntent.getActivity( getApplicationContext(), 0, resultIntent, PendingIntent.FLAG_UPDATE_CURRENT); NotificationCompat.Builder builder = new NotificationCompat.Builder( getApplicationContext()).setSmallIcon(R.drawable.ic_action_emo_wonder) .setColor(getResources().getColor(R.color.theme_primary)) .setContentTitle(privateMessage.getRecipient()) .setContentText(privateMessage.getSubject()) .setContentIntent(resultPendingIntent).setAutoCancel(true); builder.setVibrate(VIBRATION_PATTERN); notificationManager.notify((int) privateMessage.getId(), builder.build()); } } })); } // Setup next alarm long wakeUpTime = System.currentTimeMillis() + settings.getPrivateMessagesPollingFrequency() * DateUtils.MINUTE_IN_MILLIS; AlarmManager am = (AlarmManager) getSystemService(Context.ALARM_SERVICE); Intent i = new Intent(this, PrivateMessagesService.class); PendingIntent pi = PendingIntent.getService(this, 0, i, 0); Log.d(LOG_TAG, "Going to sleep, setting wake-up alarm to: " + wakeUpTime); if (AndroidUtils.isKitKatOrHigher()) { am.setExact(AlarmManager.RTC_WAKEUP, wakeUpTime, pi); } else { am.set(AlarmManager.RTC_WAKEUP, wakeUpTime, pi); } }
From source file:com.irateam.vkplayer.notifications.DownloadNotification.java
public static void errorDownload(Context context, String error) { NotificationCompat.Builder builder = new NotificationCompat.Builder(context) .setSmallIcon(R.drawable.ic_error_white_24dp) .setContentTitle(context.getString(R.string.notification_error_download_title)).setContentText( error.isEmpty() ? context.getString(R.string.notification_error_download_message) : error); NotificationManagerCompat.from(context).notify(FINAL_DOWNLOAD_NOTIFICATION_ID, builder.build()); }
From source file:com.ezhuk.wear.NotificationUtils.java
public static void showNotificationWithPages(Context context) { NotificationCompat.Builder builder = new NotificationCompat.Builder(context) .setSmallIcon(R.drawable.ic_launcher).setContentTitle(context.getString(R.string.page1_title)) .setContentText(context.getString(R.string.page1_text)); Notification second = new NotificationCompat.Builder(context).setSmallIcon(R.drawable.ic_launcher) .setContentTitle(context.getString(R.string.page2_title)) .setContentText(context.getString(R.string.page2_text)).build(); NotificationManagerCompat.from(context).notify(getNewID(), new WearableExtender().addPage(second).extend(builder).build()); }
From source file:at.bitfire.davdroid.ui.PermissionsActivity.java
protected void refresh() { boolean noCalendarPermissions = ActivityCompat.checkSelfPermission(this, Manifest.permission.READ_CALENDAR) != PackageManager.PERMISSION_GRANTED || ActivityCompat.checkSelfPermission(this, Manifest.permission.WRITE_CALENDAR) != PackageManager.PERMISSION_GRANTED; findViewById(R.id.calendar_permissions).setVisibility(noCalendarPermissions ? View.VISIBLE : View.GONE); boolean noContactsPermissions = ActivityCompat.checkSelfPermission(this, Manifest.permission.READ_CONTACTS) != PackageManager.PERMISSION_GRANTED || ActivityCompat.checkSelfPermission(this, Manifest.permission.WRITE_CONTACTS) != PackageManager.PERMISSION_GRANTED; findViewById(R.id.contacts_permissions).setVisibility(noContactsPermissions ? View.VISIBLE : View.GONE); boolean noTaskPermissions; if (LocalTaskList.tasksProviderAvailable(this)) { noTaskPermissions = ActivityCompat.checkSelfPermission(this, PERMISSION_READ_TASKS) != PackageManager.PERMISSION_GRANTED || ActivityCompat.checkSelfPermission(this, PERMISSION_WRITE_TASKS) != PackageManager.PERMISSION_GRANTED; findViewById(R.id.opentasks_permissions).setVisibility(noTaskPermissions ? View.VISIBLE : View.GONE); } else {/*from w w w.j a v a 2s . c o m*/ findViewById(R.id.opentasks_permissions).setVisibility(View.GONE); noTaskPermissions = false; } if (!noCalendarPermissions && !noContactsPermissions && !noTaskPermissions) { NotificationManagerCompat nm = NotificationManagerCompat.from(this); nm.cancel(Constants.NOTIFICATION_PERMISSIONS); finish(); } }
From source file:com.google.android.apps.santatracker.PhoneNotificationService.java
@Override public void onDataChanged(DataEventBuffer dataEvents) { for (DataEvent dataEvent : dataEvents) { if (dataEvent.getType() == DataEvent.TYPE_DELETED) { // A notification has been deleted on the watch and it modified the DataApi to // notify us. // Only one notification shown at a time, so dismiss it NotificationManagerCompat.from(this).cancelAll(); }//from ww w.j av a 2 s. co m } }
From source file:com.actinarium.nagbox.service.NotificationHelper.java
private static void fireForMultipleTasks(Context context, Task[] tasks) { long currentTime = System.currentTimeMillis(); final NotificationManagerCompat notifManager = NotificationManagerCompat.from(context); final int tasksCount = tasks.length; // Create a group of stacked notifications for (Task task : tasks) { // Notification action to stop the task Intent stopAction = new Intent(context, NagboxService.class); stopAction.setAction(NagboxService.ACTION_ON_NOTIFICATION_ACTION_STOP_TASK); stopAction.putExtra(NagboxService.EXTRA_TASK_ID, task.id); stopAction.putExtra(NagboxService.EXTRA_CANCEL_NOTIFICATION_ID, (int) task.id); // Since actions are "equal" (differ in extras only), need to use a unique "request code" (task.id will do) PendingIntent stopActionPI = PendingIntent.getService(context, (int) task.id, stopAction, PendingIntent.FLAG_UPDATE_CURRENT); Notification stackedItem = makeCommonBuilder(context, currentTime, task.id).setContentTitle(task.title) .setContentText(DateUtils.prettyPrintNagDuration(context, task.lastStartedAt, currentTime)) .setGroup(NAG_NOTIFICATION_GROUP).addAction(R.drawable.ic_cancel, context.getString(R.string.notification_action_stop), stopActionPI) .build();/*from w w w .ja v a 2s .c o m*/ // Well, let's use task IDs for their individual notifications then notifManager.notify((int) task.id, stackedItem); } // Summary text, reused final String summary = context.getResources().getQuantityString(R.plurals.notification_stacked_header, tasksCount, tasksCount); // Public summary notification // Since Android N already shows app name in the notification, display the summary in title boolean isApi24 = Build.VERSION.SDK_INT >= 24; Notification publicNotification = makeCommonBuilder(context, currentTime, Task.NO_ID) .setContentTitle(isApi24 ? summary : context.getString(R.string.app_name)) .setContentText(isApi24 ? null : summary).setGroup(NAG_NOTIFICATION_GROUP).setGroupSummary(true) .build(); // Create expanded (inbox style) for private notification. // If there are more than 5 tasks, enlist first 4 and add +x more NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle(); inboxStyle.setBigContentTitle(summary); if (tasksCount <= 5) { for (Task task : tasks) { inboxStyle.addLine(makeInboxStyleLine(context, task, currentTime)); } } else { for (int i = 0; i < 4; i++) { inboxStyle.addLine(makeInboxStyleLine(context, tasks[i], currentTime)); } inboxStyle.addLine(context.getString(R.string.notification_stack_overflow, tasksCount - 4)); } // Create private summary notification Notification privateNotification = makeCommonBuilder(context, currentTime, Task.NO_ID) .setPublicVersion(publicNotification) .setContentTitle(isApi24 ? summary : context.getString(R.string.app_name)) .setContentText(isApi24 ? null : summary).setStyle(inboxStyle).setGroup(NAG_NOTIFICATION_GROUP) .setGroupSummary(true).build(); notifManager.notify(NAG_NOTIFICATION_ID, privateNotification); }
From source file:com.commonsware.android.messaging.RemoteInputReceiver.java
@Override public void onReceive(Context ctxt, Intent i) { Bundle input = RemoteInput.getResultsFromIntent(i); if (input != null) { CharSequence text = input.getCharSequence(EXTRA_INPUT); if (text != null) { MESSAGES.push(new Message(text)); } else {// ww w.j a v a 2 s. c o m Log.e(getClass().getSimpleName(), "No voice response speech"); } } else { Log.e(getClass().getSimpleName(), "No voice response Bundle"); } NotificationManagerCompat.from(ctxt).notify(RemoteInputReceiver.NOTIFY_ID, buildNotification(ctxt).build()); }
From source file:com.example.android.google.wearable.app.MainActivity.java
/** * Handles the button to launch a notification. *//*from w ww . jav a 2s .c o m*/ public void showNotification(View view) { Notification notification = new NotificationCompat.Builder(this) .setContentTitle(getString(R.string.notification_title)) .setContentText(getString(R.string.notification_title)).setSmallIcon(R.drawable.ic_launcher) .addAction(R.drawable.ic_launcher, getText(R.string.action_launch_activity), PendingIntent.getActivity(this, NOTIFICATION_REQUEST_CODE, new Intent(this, GridExampleActivity.class), PendingIntent.FLAG_UPDATE_CURRENT)) .build(); NotificationManagerCompat.from(this).notify(NOTIFICATION_ID, notification); finish(); }