@Override public boolean onStartJob(JobParameters params) { NotificationManager mgr= (NotificationManager)getSystemService(NOTIFICATION_SERVICE); if (Build.VERSION.SDK_INT>=Build.VERSION_CODES.O && mgr.getNotificationChannel(CHANNEL_WHATEVER)==null) { mgr.createNotificationChannel(new NotificationChannel(CHANNEL_WHATEVER, "Whatever", NotificationManager.IMPORTANCE_DEFAULT)); } NotificationCompat.Builder b= new NotificationCompat.Builder(this, CHANNEL_WHATEVER) .setAutoCancel(true) .setDefaults(Notification.DEFAULT_ALL) .setContentTitle("You added a contact!") .setSmallIcon(android.R.drawable.stat_notify_more); mgr.notify(NOTIFY_ID, b.build()); return(false); }
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); NotificationManager mgr= (NotificationManager)getSystemService(NOTIFICATION_SERVICE); if (Build.VERSION.SDK_INT>=Build.VERSION_CODES.O && mgr.getNotificationChannel(CHANNEL_WHATEVER)==null) { mgr.createNotificationChannel(new NotificationChannel(CHANNEL_WHATEVER, "Whatever", NotificationManager.IMPORTANCE_DEFAULT)); } mgr.notify(NOTIFY_ID, buildNormal().build()); finish(); }
public static Notification buildNotification(Context context, Notification.Builder builder) { builder.setSmallIcon(R.drawable.leak_canary_notification) .setWhen(System.currentTimeMillis()) .setOnlyAlertOnce(true); if (SDK_INT >= O) { NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); NotificationChannel notificationChannel = notificationManager.getNotificationChannel(NOTIFICATION_CHANNEL_ID); if (notificationChannel == null) { String channelName = context.getString(R.string.leak_canary_notification_channel); notificationChannel = new NotificationChannel(NOTIFICATION_CHANNEL_ID, channelName, NotificationManager.IMPORTANCE_DEFAULT); notificationManager.createNotificationChannel(notificationChannel); } builder.setChannelId(NOTIFICATION_CHANNEL_ID); } if (SDK_INT < JELLY_BEAN) { return builder.getNotification(); } else { return builder.build(); } }
mgr.getNotificationChannel(CHANNEL_WHATEVER)==null) { mgr.createNotificationChannel(new NotificationChannel(CHANNEL_WHATEVER, "Whatever", NotificationManager.IMPORTANCE_DEFAULT));
mgr.getNotificationChannel(CHANNEL_WHATEVER)==null) { mgr.createNotificationChannel(new NotificationChannel(CHANNEL_WHATEVER, "Whatever", NotificationManager.IMPORTANCE_DEFAULT));
mgr.getNotificationChannel(CHANNEL_WHATEVER)==null) { mgr.createNotificationChannel(new NotificationChannel(CHANNEL_WHATEVER, "Whatever", NotificationManager.IMPORTANCE_DEFAULT));
mgr.getNotificationChannel(CHANNEL_WHATEVER)==null) { mgr.createNotificationChannel(new NotificationChannel(CHANNEL_WHATEVER, "Whatever", NotificationManager.IMPORTANCE_DEFAULT));
@Override public void onReceive(Context ctxt, Intent i) { NotificationManager mgr= (NotificationManager)ctxt.getSystemService(Context.NOTIFICATION_SERVICE); if (Build.VERSION.SDK_INT>=Build.VERSION_CODES.O && mgr.getNotificationChannel(CHANNEL_WHATEVER)==null) { mgr.createNotificationChannel(new NotificationChannel(CHANNEL_WHATEVER, "Whatever", NotificationManager.IMPORTANCE_DEFAULT)); mgr.createNotificationChannel(new NotificationChannel(CHANNEL_HEADS_UP, "Heads Up!", NotificationManager.IMPORTANCE_HIGH)); } NotificationManagerCompat mgrCompat=NotificationManagerCompat.from(ctxt); switch (i.getIntExtra(EXTRA_TYPE, -1)) { case 0: notifyPrivate(ctxt, mgrCompat); break; case 1: notifyPublic(ctxt, mgrCompat); break; case 2: notifySecret(ctxt, mgrCompat); break; case 3: notifyHeadsUp(ctxt, mgrCompat); break; } }
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); NotificationManager mgr= (NotificationManager)getSystemService(NOTIFICATION_SERVICE); if (Build.VERSION.SDK_INT>=Build.VERSION_CODES.O && mgr.getNotificationChannel(CHANNEL_WHATEVER)==null) { mgr.createNotificationChannel(new NotificationChannel(CHANNEL_WHATEVER, "Whatever", NotificationManager.IMPORTANCE_DEFAULT)); } mgrCompat=NotificationManagerCompat.from(this); showWearOne(); showWearTwo(); showSummary(); finish(); }
@Override public void onCreate() { super.onCreate(); rxBluetooth=new RxBluetooth(getApplicationContext()); acceptConnections(); NotificationManager mgr= (NotificationManager)getSystemService(NOTIFICATION_SERVICE); if (Build.VERSION.SDK_INT>=Build.VERSION_CODES.O && mgr.getNotificationChannel(CHANNEL_WHATEVER)==null) { mgr.createNotificationChannel(new NotificationChannel(CHANNEL_WHATEVER, "Whatever", NotificationManager.IMPORTANCE_DEFAULT)); } startForeground(1338, buildForegroundNotification()); STATUS.postValue(Status.IS_RUNNING); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); mgr=getSystemService(NotificationManager.class); if (mgr.getNotificationChannel(CHANNEL_CONTENT)==null) { initGroups(); initContentChannel(); initBattleChannel(); initCoinsChannel(); } setContentView(R.layout.activity_main); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); mgr=getSystemService(NotificationManager.class); if (mgr.getNotificationChannel(CHANNEL_CONTENT)==null) { initGroups(); initContentChannel(); initBattleChannel(); initCoinsChannel(); } setContentView(R.layout.activity_main); }
private void showNotification() { NotificationManager mgr= (NotificationManager)getSystemService(NOTIFICATION_SERVICE); if (Build.VERSION.SDK_INT>=Build.VERSION_CODES.O && mgr.getNotificationChannel(CHANNEL_WHATEVER)==null) { mgr.createNotificationChannel(new NotificationChannel(CHANNEL_WHATEVER, "Whatever", NotificationManager.IMPORTANCE_DEFAULT)); } NotificationCompat.Builder b= new NotificationCompat.Builder(this, CHANNEL_WHATEVER) .setOngoing(true) .setContentTitle("Presentation!") .setSmallIcon(android.R.drawable.stat_notify_more) .addAction(android.R.drawable.ic_media_previous, getString(R.string.action_previous), buildPreviousPendingIntent()) .addAction(android.R.drawable.ic_media_next, getString(R.string.action_next), buildNextPendingIntent()) .addAction(android.R.drawable.ic_media_pause, getString(R.string.action_stop), buildStopPendingIntent()); mgr.notify(1337, b.build()); }
private void foregroundify() { NotificationManager mgr= (NotificationManager)getSystemService(NOTIFICATION_SERVICE); if (Build.VERSION.SDK_INT>=Build.VERSION_CODES.O && mgr.getNotificationChannel(CHANNEL_WHATEVER)==null) { mgr.createNotificationChannel(new NotificationChannel(CHANNEL_WHATEVER, "Whatever", NotificationManager.IMPORTANCE_DEFAULT)); } NotificationCompat.Builder b= new NotificationCompat.Builder(this, CHANNEL_WHATEVER); b.setAutoCancel(true) .setDefaults(Notification.DEFAULT_ALL); b.setContentTitle(getString(R.string.app_name)) .setSmallIcon(R.mipmap.ic_launcher) .setTicker(getString(R.string.app_name)); b.addAction(R.drawable.ic_record_white_24dp, getString(R.string.notify_record), buildPendingIntent(ACTION_RECORD)); b.addAction(R.drawable.ic_eject_white_24dp, getString(R.string.notify_shutdown), buildPendingIntent(ACTION_SHUTDOWN)); startForeground(NOTIFY_ID, b.build()); }
mgr.getNotificationChannel(CHANNEL_WHATEVER)==null) { mgr.createNotificationChannel(new NotificationChannel(CHANNEL_WHATEVER, "Whatever", NotificationManager.IMPORTANCE_DEFAULT));
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); NotificationManager mgr= (NotificationManager)getSystemService(NOTIFICATION_SERVICE); if (Build.VERSION.SDK_INT>=Build.VERSION_CODES.O && mgr.getNotificationChannel(CHANNEL_WHATEVER)==null) { mgr.createNotificationChannel(new NotificationChannel(CHANNEL_WHATEVER, "Whatever", NotificationManager.IMPORTANCE_DEFAULT)); } NotificationCompat.Builder normal=buildNormal(); NotificationCompat.Action.Builder wearActionBuilder= new NotificationCompat.Action.Builder(android.R.drawable.ic_media_pause, getString(R.string.pause), buildPendingIntent(Settings.ACTION_DATE_SETTINGS)); NotificationCompat.Builder extended= new NotificationCompat.WearableExtender() .addAction(wearActionBuilder.build()) .extend(normal); NotificationManagerCompat.from(this).notify(NOTIFY_ID, extended.build()); finish(); }
@Test @Config(minSdk = Build.VERSION_CODES.O) public void deleteNotificationChannel() { final String channelId = "channelId"; assertThat(shadowOf(notificationManager).isChannelDeleted(channelId)).isFalse(); notificationManager.createNotificationChannel(new NotificationChannel(channelId, "name", 1)); assertThat(shadowOf(notificationManager).isChannelDeleted(channelId)).isFalse(); notificationManager.deleteNotificationChannel(channelId); assertThat(shadowOf(notificationManager).isChannelDeleted(channelId)).isTrue(); assertThat(notificationManager.getNotificationChannel(channelId)).isNull(); // Per documentation, recreating a deleted channel should have the same settings as the old // deleted channel. notificationManager.createNotificationChannel( new NotificationChannel(channelId, "otherName", 2)); assertThat(shadowOf(notificationManager).isChannelDeleted(channelId)).isFalse(); NotificationChannel channel = notificationManager.getNotificationChannel(channelId); assertThat(channel.getName()).isEqualTo("name"); assertThat(channel.getImportance()).isEqualTo(1); }
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); NotificationManager mgr= (NotificationManager)getSystemService(NOTIFICATION_SERVICE); if (Build.VERSION.SDK_INT>=Build.VERSION_CODES.O && mgr.getNotificationChannel(CHANNEL_WHATEVER)==null) { mgr.createNotificationChannel(new NotificationChannel(CHANNEL_WHATEVER, "Whatever", NotificationManager.IMPORTANCE_DEFAULT)); } NotificationCompat.Builder normal=buildNormal(); NotificationCompat.InboxStyle big= new NotificationCompat.InboxStyle(normal); mgr.notify(NOTIFY_ID, big.setSummaryText(getString(R.string.summary)) .addLine(getString(R.string.entry)) .addLine(getString(R.string.another_entry)) .addLine(getString(R.string.third_entry)) .addLine(getString(R.string.yet_another_entry)) .addLine(getString(R.string.low)).build()); finish(); }
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); NotificationManager mgr= (NotificationManager)getSystemService(NOTIFICATION_SERVICE); if (Build.VERSION.SDK_INT>=Build.VERSION_CODES.O && mgr.getNotificationChannel(CHANNEL_WHATEVER)==null) { mgr.createNotificationChannel(new NotificationChannel(CHANNEL_WHATEVER, "Whatever", NotificationManager.IMPORTANCE_DEFAULT)); } NotificationCompat.Builder normal=buildNormal(); NotificationCompat.InboxStyle big= new NotificationCompat.InboxStyle(normal); mgr.notify(NOTIFY_ID, big.setSummaryText(getString(R.string.summary)) .addLine(getString(R.string.entry)) .addLine(getString(R.string.another_entry)) .addLine(getString(R.string.third_entry)) .addLine(getString(R.string.yet_another_entry)) .addLine(getString(R.string.low)).build()); finish(); }
mgr.getNotificationChannel(CHANNEL_WHATEVER)==null) { mgr.createNotificationChannel(new NotificationChannel(CHANNEL_WHATEVER, "Whatever", NotificationManager.IMPORTANCE_DEFAULT));