I want to send a notification → There are many ways → It seems stable to use NotificationCompat.Builder
First of all, the notification is not displayed → Set the icon → Notification Channel required (Android O or later only)
I want to issue a head-up notification → Not → Raise priority → Allow vibration → Various others → Notification Channel needs to be set → The settings remain until you uninstall
** It's hard because the required information is too different for each API Level **
private void notice()
{
final String CHANNEL_ID = "sample_notification_channel";
final int ID = 0;
NotificationCompat.Builder mBuilder;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
NotificationChannel channel = new NotificationChannel(CHANNEL_ID,"This is notificationChannel1",NotificationManager.IMPORTANCE_HIGH);
channel.setLockscreenVisibility(Notification.VISIBILITY_PUBLIC);
channel.enableVibration(true);
NotificationManager manager = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
manager.createNotificationChannel(channel);
mBuilder = new NotificationCompat.Builder(this, CHANNEL_ID);
}else{
mBuilder = new NotificationCompat.Builder(this);
}
mBuilder.setSmallIcon(R.drawable.ic_stat_name)
.setContentTitle("ApduService")
.setContentText("processCommandApdu")
.setColor(Color.rgb(0,255,0))
.setDefaults(Notification.DEFAULT_ALL)
.setAutoCancel(true)
.setWhen(System.currentTimeMillis())
.setPriority(Notification.PRIORITY_HIGH)
.setVibrate(new long[]{100, 0, 100, 0, 100, 0});
NotificationManagerCompat manager = NotificationManagerCompat.from(this);
manager.notify(ID, mBuilder.build());
}
}
[Android] Notify Alarm with NotificationManager https://akira-watson.com/android/alarm-notificationmanager.html
I tried a little with the behavior of the notification channel of Android by changing the targetSDKVersion of the project http://woshidan.hatenablog.com/entry/2017/08/23/083000
Customize Android notifications (API21 or later) https://qiita.com/sakebook/items/8cafc0766b4f8dc95994
[Android] Customize notifications! http://www.eda-inc.jp/post-622/
Try using the Android O notification channel http://blog.techium.jp/entry/2017/09/11/090000
Solved the problem that the notification icon became white on Android 5.0 Lolipop and above https://qiita.com/syarihu/items/95788cbab9b63100c4fb
How to send a notification to the status bar with the Android app. https://qiita.com/steroid66/items/27f5ce27eb32eae49732
Recommended Posts