/* package */ Notification processNotification(Notification notification) { switch (mSoundMode) { case OVERRIDE: notification.sound = mSoundOverride; break; case SUPPRESS: silenceNotification(notification); break; case DEFAULT: } switch (mVibrateMode) { case OVERRIDE: notification.defaults |= Notification.DEFAULT_VIBRATE; break; case SUPPRESS: suppressVibrate(notification); break; case DEFAULT: } switch (mLightsMode) { case OVERRIDE: notification.defaults |= Notification.DEFAULT_LIGHTS; break; case SUPPRESS: suppressLights(notification); break; case DEFAULT: } return notification; }
/** * Creates the notification object. * * @see #setNormalNotification * @see #setBigTextStyleNotification * @see #setBigPictureStyleNotification * @see #setInboxStyleNotification */ @Override protected Void doInBackground(Void... params) { Notification noti = new Notification(); switch (style) { case NORMAL: noti = setNormalNotification(); break; case BIG_TEXT_STYLE: noti = setBigTextStyleNotification(); break; case BIG_PICTURE_STYLE: noti = setBigPictureStyleNotification(); break; case INBOX_STYLE: noti = setInboxStyleNotification(); break; case CUSTOM_VIEW: noti = setCustomViewNotification(); break; } noti.defaults |= Notification.DEFAULT_LIGHTS; noti.defaults |= Notification.DEFAULT_VIBRATE; noti.defaults |= Notification.DEFAULT_SOUND; noti.flags |= Notification.FLAG_ONLY_ALERT_ONCE; mNotificationManager.notify(0, noti); return null; }
public void showNotification(String title, String message) { Intent notifyIntent = new Intent(this, MainActivity.class); notifyIntent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP); PendingIntent pendingIntent = PendingIntent.getActivities( this, 0, new Intent[] {notifyIntent}, PendingIntent.FLAG_UPDATE_CURRENT); Notification notification = new Notification.Builder(this) .setSmallIcon(android.R.drawable.ic_dialog_info) .setContentTitle(title) .setContentText(message) .setAutoCancel(true) .setContentIntent(pendingIntent) .build(); notification.defaults |= Notification.DEFAULT_SOUND; NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.notify(1, notification); }
private void suppressLights(Notification notification) { notification.defaults &= (~Notification.DEFAULT_LIGHTS); notification.flags &= (~Notification.FLAG_SHOW_LIGHTS); }
private void suppressVibrate(Notification notification) { notification.defaults &= (~Notification.DEFAULT_VIBRATE); notification.vibrate = null; }
private void silenceNotification(Notification notification) { notification.defaults &= (~Notification.DEFAULT_SOUND); notification.sound = null; }