List of usage examples for android.support.v4.app NotificationManagerCompat from
public static NotificationManagerCompat from(Context context)
From source file:nu.yona.app.ui.YonaActivity.java
private void checkForNotificationPermission() { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O || (NotificationManagerCompat.from(this).areNotificationsEnabled() && AppUtils.arePersistentNotificationsEnabled(getActivity()))) { return;//from w w w . j av a 2 s .c o m } Logger.loge("Notifications Disabled", this.getString(R.string.notification_disabled_message)); AppUtils.displayErrorAlert(getActivity(), new ErrorMessage(this.getString(R.string.notification_disabled_message))); }
From source file:com.onesignal.GenerateNotification.java
private static int showNotification(JSONObject gcmBundle) { Random random = new Random(); String group = null;/*from w ww .j a va 2s . c o m*/ try { group = gcmBundle.getString("grp"); } catch (Throwable t) { } int notificationId = random.nextInt(); NotificationCompat.Builder notifBuilder = getBaseNotificationCompatBuilder(gcmBundle, true); addNotificationActionButtons(gcmBundle, notifBuilder, notificationId, null); if (group != null) { PendingIntent contentIntent = getNewActionPendingIntent(random.nextInt(), getNewBaseIntent(notificationId).putExtra("onesignal_data", gcmBundle.toString()) .putExtra("grp", group)); notifBuilder.setContentIntent(contentIntent); PendingIntent deleteIntent = getNewActionPendingIntent(random.nextInt(), getNewBaseDeleteIntent(notificationId).putExtra("grp", group)); notifBuilder.setDeleteIntent(deleteIntent); notifBuilder.setGroup(group); createSummaryNotification(gcmBundle); } else { PendingIntent contentIntent = getNewActionPendingIntent(random.nextInt(), getNewBaseIntent(notificationId).putExtra("onesignal_data", gcmBundle.toString())); notifBuilder.setContentIntent(contentIntent); PendingIntent deleteIntent = getNewActionPendingIntent(random.nextInt(), getNewBaseDeleteIntent(notificationId)); notifBuilder.setDeleteIntent(deleteIntent); } // NotificationManagerCompat does not auto omit the individual notification on the device when using // stacked notifications on Android 4.2 and older // The benefits of calling notify for individual notifications in-addition to the summary above it is shows // each notification in a stack on Android Wear and each one is actionable just like the Gmail app does per email. if (group == null || android.os.Build.VERSION.SDK_INT > Build.VERSION_CODES.JELLY_BEAN_MR1) NotificationManagerCompat.from(currentContext).notify(notificationId, notifBuilder.build()); return notificationId; }
From source file:com.cnlms.wear.NotificationHelper.java
public static void raiseNotificaiontAndGetReplyWithVoiceInput(final Context context) { final RemoteInput remoteInput = new RemoteInput.Builder(EXTRA_VOICE_REPLY).setLabel("Rate the session") .setChoices(context.getResources().getStringArray(R.array.reply_choices)).build(); final int notificationId = 1; final NotificationCompat.Builder builder = new NotificationCompat.Builder(context) .setSmallIcon(R.drawable.ic_notif).setContentTitle("Was the session helpful?") .setContentIntent(openSessionDetailsIntent(context)) .setLargeIcon(BitmapFactory.decodeResource(context.getResources(), R.drawable.bg_gdg)); builder.extend(new NotificationCompat.WearableExtender() .addAction(new NotificationCompat.Action.Builder(R.drawable.abc_ic_voice_search_api_mtrl_alpha, "Reply", openSessionDetailsIntent(context)).addRemoteInput(remoteInput).build())); NotificationManagerCompat.from(context).notify(notificationId, builder.build()); }
From source file:id.satusatudua.sigap.service.NotificationService.java
private void showNotification(String userId) { PendingIntent pendingIntent = PendingIntent.getActivity(getApplicationContext(), 0, ConfirmTrustedOfActivity.generateIntent(this, userId), PendingIntent.FLAG_UPDATE_CURRENT); Notification notification = new NotificationCompat.Builder(getApplicationContext()).setContentTitle("Sigap") .setContentText("Seseorang menambahkanmu kedalam kontak terpercayanya!") .setSmallIcon(R.mipmap.ic_launcher) .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher)) .setVibrate(CacheManager.pluck().isVibrate() ? new long[] { 100, 300, 500, 1000 } : new long[] {}) .setSound(Uri.parse(CacheManager.pluck().getRingtone())).setAutoCancel(true) .setStyle(new android.support.v4.app.NotificationCompat.BigTextStyle().bigText( "Seseorang menambahkanmu kedalam kontak terpercayanya!, klik untuk mengkonfirmasi.")) .setContentIntent(pendingIntent).build(); NotificationManagerCompat.from(SigapApp.pluck().getApplicationContext()) .notify(BenihUtils.randInt(1, Integer.MAX_VALUE), notification); }
From source file:org.smssecure.smssecure.notifications.MessageNotifier.java
private static void sendMultipleThreadNotification(Context context, NotificationState notificationState, int flags) { MultipleRecipientNotificationBuilder builder = new MultipleRecipientNotificationBuilder(context, SilencePreferences.getNotificationPrivacy(context)); List<NotificationItem> notifications = notificationState.getNotifications(); builder.setMessageCount(notificationState.getMessageCount(), notificationState.getThreadCount()); builder.setMostRecentSender(notifications.get(0).getIndividualRecipient()); builder.setGroup(NOTIFICATION_GROUP); builder.setDeleteIntent(notificationState.getDeleteIntent(context)); long timestamp = notifications.get(0).getTimestamp(); if (timestamp != 0) builder.setWhen(timestamp);/*from w ww. ja v a 2 s .c o m*/ builder.addActions(notificationState.getMarkAsReadIntent(context, SUMMARY_NOTIFICATION_ID)); ListIterator<NotificationItem> iterator = notifications.listIterator(0); while (iterator.hasNext()) { NotificationItem item = iterator.next(); builder.addMessageBody(item.getIndividualRecipient(), item.getText()); } if (notificationsRequested(flags)) { triggerNotificationAlarms(builder, notificationState, flags); builder.setTicker(notifications.get(0).getIndividualRecipient(), notifications.get(0).getText()); } NotificationManagerCompat.from(context).notify(SUMMARY_NOTIFICATION_ID, builder.build()); }
From source file:com.android.mail.utils.NotificationUtils.java
/** * Get all notifications for all accounts and cancel them. **///from w w w.j a v a 2s . c o m public static void cancelAllNotifications(Context context) { LogUtils.d(LOG_TAG, "cancelAllNotifications - cancelling all"); NotificationManagerCompat nm = NotificationManagerCompat.from(context); nm.cancelAll(); clearAllNotfications(context); }
From source file:com.devalladolid.musictoday.MusicService.java
@Override public void onCreate() { if (D)// w w w . j a v a 2 s.c o m Log.d(TAG, "Creating service"); super.onCreate(); mNotificationManager = NotificationManagerCompat.from(this); // gets a pointer to the playback state store mPlaybackStateStore = MusicPlaybackState.getInstance(this); mSongPlayCount = SongPlayCount.getInstance(this); mRecentStore = RecentStore.getInstance(this); mHandlerThread = new HandlerThread("MusicPlayerHandler", android.os.Process.THREAD_PRIORITY_BACKGROUND); mHandlerThread.start(); mPlayerHandler = new MusicPlayerHandler(this, mHandlerThread.getLooper()); mAudioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE); mMediaButtonReceiverComponent = new ComponentName(getPackageName(), MediaButtonIntentReceiver.class.getName()); mAudioManager.registerMediaButtonEventReceiver(mMediaButtonReceiverComponent); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) setUpMediaSession(); mPreferences = getSharedPreferences("Service", 0); mCardId = getCardId(); registerExternalStorageListener(); mPlayer = new MultiPlayer(this); mPlayer.setHandler(mPlayerHandler); // Initialize the intent filter and each action final IntentFilter filter = new IntentFilter(); filter.addAction(SERVICECMD); filter.addAction(TOGGLEPAUSE_ACTION); filter.addAction(PAUSE_ACTION); filter.addAction(STOP_ACTION); filter.addAction(NEXT_ACTION); filter.addAction(PREVIOUS_ACTION); filter.addAction(PREVIOUS_FORCE_ACTION); filter.addAction(REPEAT_ACTION); filter.addAction(SHUFFLE_ACTION); // Attach the broadcast listener registerReceiver(mIntentReceiver, filter); mMediaStoreObserver = new MediaStoreObserver(mPlayerHandler); getContentResolver().registerContentObserver(MediaStore.Audio.Media.INTERNAL_CONTENT_URI, true, mMediaStoreObserver); getContentResolver().registerContentObserver(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, true, mMediaStoreObserver); // Initialize the wake lock final PowerManager powerManager = (PowerManager) getSystemService(Context.POWER_SERVICE); mWakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, getClass().getName()); mWakeLock.setReferenceCounted(false); final Intent shutdownIntent = new Intent(this, MusicService.class); shutdownIntent.setAction(SHUTDOWN); mAlarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE); mShutdownIntent = PendingIntent.getService(this, 0, shutdownIntent, 0); scheduleDelayedShutdown(); reloadQueueAfterPermissionCheck(); notifyChange(QUEUE_CHANGED); notifyChange(META_CHANGED); }
From source file:com.ruesga.rview.misc.NotificationsHelper.java
private static void publishNotification(Context ctx, Notification notification, int groupId) { NotificationManagerCompat notificationManager = NotificationManagerCompat.from(ctx); notificationManager.notify(groupId, notification); }
From source file:com.androidinspain.deskclock.alarms.AlarmNotifications.java
static synchronized void showSnoozeNotification(Context context, AlarmInstance instance) { LogUtils.v("Displaying snoozed notification for alarm instance: " + instance.mId); NotificationCompat.Builder builder = new NotificationCompat.Builder(context).setShowWhen(false) .setContentTitle(instance.getLabelOrDefault(context)) .setContentText(context.getString(com.androidinspain.deskclock.R.string.alarm_alert_snooze_until, AlarmUtils.getFormattedTime(context, instance.getAlarmTime()))) .setColor(ContextCompat.getColor(context, com.androidinspain.deskclock.R.color.default_background)) .setSmallIcon(com.androidinspain.deskclock.R.drawable.stat_notify_alarm).setAutoCancel(false) .setSortKey(createSortKey(instance)).setPriority(NotificationCompat.PRIORITY_MAX) .setCategory(NotificationCompat.CATEGORY_ALARM).setVisibility(NotificationCompat.VISIBILITY_PUBLIC) .setLocalOnly(true);//w w w .ja v a 2 s .c o m if (Utils.isNOrLater()) { builder.setGroup(UPCOMING_GROUP_KEY); } // Setup up dismiss action Intent dismissIntent = AlarmStateManager.createStateChangeIntent(context, AlarmStateManager.ALARM_DISMISS_TAG, instance, AlarmInstance.DISMISSED_STATE); final int id = instance.hashCode(); builder.addAction(com.androidinspain.deskclock.R.drawable.ic_alarm_off_24dp, context.getString(com.androidinspain.deskclock.R.string.alarm_alert_dismiss_text), PendingIntent.getService(context, id, dismissIntent, PendingIntent.FLAG_UPDATE_CURRENT)); // Setup content action if instance is owned by alarm Intent viewAlarmIntent = createViewAlarmIntent(context, instance); builder.setContentIntent( PendingIntent.getActivity(context, id, viewAlarmIntent, PendingIntent.FLAG_UPDATE_CURRENT)); NotificationManagerCompat nm = NotificationManagerCompat.from(context); final Notification notification = builder.build(); nm.notify(id, notification); updateUpcomingAlarmGroupNotification(context, -1, notification); }
From source file:com.google.fpl.gim.examplegame.MainService.java
/** * Builds and posts a notification from a set of options. * @param options The options to build the notification. *///from w w w . ja v a2 s . co m public void postActionNotification(NotificationOptions options) { NotificationCompat.Builder builder = new NotificationCompat.Builder(this); builder.setSmallIcon(options.getSmallIconResourceId()); builder.setContentTitle(options.getTitle()); builder.setContentText(options.getContent()); builder.setDefaults(options.getNotificationDefaults()); builder.setPriority(options.getNotificationPriority()); builder.setVibrate(options.getVibratePattern()); if (options.getActions() != null) { for (NotificationCompat.Action action : options.getActions()) { builder.addAction(action); } } NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this); notificationManager.notify(options.getNotificationId(), builder.build()); }