List of usage examples for android.app Notification CATEGORY_ALARM
String CATEGORY_ALARM
To view the source code for android.app Notification CATEGORY_ALARM.
Click Source Link
From source file:com.example.alarmmanager.AlarmIntentService.java
@Override protected void onHandleIntent(Intent intent) { Context context = getApplicationContext(); String date = intent.getStringExtra("DATE"); Log.d(TAG, "Received alarm event: " + date); NotificationManager notificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); NotificationCompat.Builder builder = new NotificationCompat.Builder(context) .setSmallIcon(R.drawable.ic_alarm_black_24dp).setCategory(Notification.CATEGORY_ALARM) .setSound(Settings.System.DEFAULT_ALARM_ALERT_URI).setContentTitle("Requested time : " + date); notificationManager.notify(0, builder.build()); }
From source file:com.example.android.directboot.alarms.AlarmIntentService.java
@Override protected void onHandleIntent(Intent intent) { Context context = getApplicationContext(); Alarm alarm = intent.getParcelableExtra(ALARM_KEY); NotificationManager notificationManager = context.getSystemService(NotificationManager.class); NotificationCompat.Builder builder = new NotificationCompat.Builder(context) .setSmallIcon(R.drawable.ic_fbe_notification).setCategory(Notification.CATEGORY_ALARM) .setSound(Settings.System.DEFAULT_ALARM_ALERT_URI) .setContentTitle(context.getString(R.string.alarm_went_off, alarm.hour, alarm.minute)); notificationManager.notify(alarm.id, builder.build()); AlarmStorage alarmStorage = new AlarmStorage(context); alarmStorage.deleteAlarm(alarm);// ww w . j a va2 s .co m Intent wentOffIntent = new Intent(ALARM_WENT_OFF_ACTION); wentOffIntent.putExtra(ALARM_KEY, alarm); LocalBroadcastManager.getInstance(context).sendBroadcast(wentOffIntent); }
From source file:com.licenta.android.licenseapp.SchedulingService.java
private void sendNotification(String msg) { mNotificationManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE); Intent intentDismiss = new Intent(this, MainTabActivity.class); intentDismiss.putExtra(Constants.KEY_NOTIFICATION_ID, Constants.ALARM_ID); intentDismiss.putExtra(Constants.KEY_DISMISS_ALARM, true); PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intentDismiss, PendingIntent.FLAG_UPDATE_CURRENT); Uri alarmSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_ALARM); NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.mipmap.ic_launcher).setContentTitle("HellO") .setStyle(new NotificationCompat.BigTextStyle().bigText(msg)).setContentText(msg) .setCategory(Notification.CATEGORY_ALARM).setSound(alarmSound); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); mBuilder.setSound(Uri.parse(prefs.getString("alarm_ringtone", ""))); if (prefs.getBoolean("alarm_vibrate", false)) mBuilder.setVibrate(new long[] { 1000, 1000 }); mBuilder.addAction(0, getString(R.string.check_in), pendingIntent); mBuilder.addAction(R.drawable.ic_stat_action_alarm_off_notif, getString(R.string.dismiss_alarm), pendingIntent);/*from ww w.j a v a 2 s . co m*/ //mBuilder.setContentIntent(contentIntent); mNotificationManager.notify(Constants.ALARM_ID, mBuilder.build()); }
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 ww .j a v a2s. c o 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:com.licenta.android.licenseapp.location.GeofenceTransitionsService.java
private void sendNotification(String msg) { NotificationManager mNotificationManager = (NotificationManager) this .getSystemService(Context.NOTIFICATION_SERVICE); Intent intentDismiss = new Intent(this, MainTabActivity.class); intentDismiss.putExtra(Constants.KEY_NOTIFICATION_ID, Constants.ALARM_ID); intentDismiss.putExtra(Constants.KEY_DISMISS_ALARM, true); PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intentDismiss, PendingIntent.FLAG_UPDATE_CURRENT); Uri alarmSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_ALARM); NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.mipmap.ic_launcher).setContentTitle("HellO") .setStyle(new NotificationCompat.BigTextStyle().bigText(msg)).setContentText(msg) .setCategory(Notification.CATEGORY_ALARM).setSound(alarmSound); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); mBuilder.setSound(Uri.parse(prefs.getString("alarm_ringtone", ""))); if (prefs.getBoolean("alarm_vibrate", false)) mBuilder.setVibrate(new long[] { 1000, 1000 }); mBuilder.addAction(0, getString(R.string.check_in), pendingIntent); mBuilder.addAction(R.drawable.ic_stat_action_alarm_off_notif, getString(R.string.dismiss_alarm), pendingIntent);//from w w w . j a va2 s.c o m //mBuilder.setContentIntent(contentIntent); mNotificationManager.notify(Constants.ALARM_ID, mBuilder.build()); }
From source file:com.amazon.rvspeedtest.GcmIntentService.java
private void sendNotification(String msg) { mNotificationManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE); PendingIntent contentIntent = PendingIntent.getActivity(this, 0, new Intent(this, MainActivity.class), 0); Uri uriSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_RINGTONE); NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.ic_stat_gcm).setContentTitle("Alexa Phone Finder") .setStyle(new NotificationCompat.BigTextStyle().bigText(msg)).setContentText(msg).setSound(uriSound) .setVibrate(new long[] { 3000, 1000, 3000, 1000, 3000, 1000, 3000 }) .setLights(Color.RED, 3000, 3000).setCategory(Notification.CATEGORY_ALARM); mBuilder.setContentIntent(contentIntent); mNotificationManager.notify(NOTIFICATION_ID, 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(); }/*from w w w .j ava 2 s. co 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.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 ww w . j a va 2 s . co 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(); }
From source file:com.brayanarias.alarmproject.activity.AlarmScreenActivity.java
private void sendNotification(String msg) { alarmNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); String title = getString(R.string.title_activity_main); Intent intent = new Intent(this, AlarmScreenActivity.class); intent.addCategory(Intent.CATEGORY_LAUNCHER); intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); Bitmap bitmap = ((BitmapDrawable) getResources().getDrawable(R.mipmap.ic_launcher)).getBitmap(); NotificationCompat.Builder alarmNotificationBuilder = new NotificationCompat.Builder(this) .setContentTitle(title).setSmallIcon(R.drawable.ic_fab_alarm).setLargeIcon(bitmap) .setCategory(Notification.CATEGORY_ALARM) .setColor(ContextCompat.getColor(getBaseContext(), R.color.colorAccent)) .setStyle(new NotificationCompat.BigTextStyle().bigText(msg)).setContentText(msg).setOngoing(true) .setContentIntent(pendingIntent); alarmNotificationManager.notify(1503, alarmNotificationBuilder.build()); }
From source file:com.lambdasoup.quickfit.alarm.AlarmService.java
@WorkerThread private void refreshNotificationDisplay() { try (Cursor toNotify = getContentResolver().query(QuickFitContentProvider.getUriWorkoutsList(), new String[] { WorkoutEntry.SCHEDULE_ID, WorkoutEntry.WORKOUT_ID, WorkoutEntry.ACTIVITY_TYPE, WorkoutEntry.LABEL, WorkoutEntry.DURATION_MINUTES }, ScheduleEntry.TABLE_NAME + "." + ScheduleEntry.COL_SHOW_NOTIFICATION + "=?", new String[] { Integer.toString(ScheduleEntry.SHOW_NOTIFICATION_YES) }, null)) { int count = toNotify == null ? 0 : toNotify.getCount(); if (count == 0) { Timber.d("refreshNotificationDisplay: no events"); NotificationManager notificationManager = (NotificationManager) getSystemService( NOTIFICATION_SERVICE); notificationManager.cancel(Constants.NOTIFICATION_ALARM); return; }//from w w w .j a v a 2s .co m long[] scheduleIds = new long[count]; int i = 0; toNotify.moveToPosition(-1); while (toNotify.moveToNext()) { scheduleIds[i] = toNotify.getLong(toNotify.getColumnIndex(WorkoutEntry.SCHEDULE_ID)); i++; } PendingIntent cancelIntent = PendingIntent.getService(getApplicationContext(), 0, getIntentOnNotificationsCanceled(this, scheduleIds), PendingIntent.FLAG_UPDATE_CURRENT); NotificationCompat.Builder notification; if (count == 1) { Timber.d("refreshNotificationDisplay: single event"); toNotify.moveToFirst(); notification = notifySingleEvent(toNotify, cancelIntent); } else { Timber.d("refreshNotificationDisplay: multiple events"); toNotify.moveToPosition(-1); notification = notifyMultipleEvents(toNotify, cancelIntent); } notification.setDeleteIntent(cancelIntent); notification.setAutoCancel(true); notification.setPriority(Notification.PRIORITY_HIGH); notification.setSmallIcon(R.drawable.ic_stat_quickfit_icon); notification.setColor(ContextCompat.getColor(this, R.color.colorPrimary)); SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this); String ringtoneUriStr = preferences.getString(getString(R.string.pref_key_notification_ringtone), null); if (ringtoneUriStr == null) { notification.setSound( RingtoneManager.getActualDefaultRingtoneUri(this, RingtoneManager.TYPE_NOTIFICATION)); } else if (!ringtoneUriStr.isEmpty()) { notification.setSound(Uri.parse(ringtoneUriStr)); } boolean ledOn = preferences.getBoolean(getString(R.string.pref_key_notification_led), true); boolean vibrationOn = preferences.getBoolean(getString(R.string.pref_key_notification_vibrate), true); notification.setDefaults( (ledOn ? Notification.DEFAULT_LIGHTS : 0) | (vibrationOn ? Notification.DEFAULT_VIBRATE : 0)); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { notification.setCategory(Notification.CATEGORY_ALARM); } NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); notificationManager.notify(Constants.NOTIFICATION_ALARM, notification.build()); } }