I'm working with Android API 28.
Through AlarmManager
, I wanted to send push Notification at certain time in Service
. So in the service, alarmManager
sets specific duration for sending push notification.
I was trying to make it, so searched for some example. It worked at 'Marshmallow 6.0, and Nougat 7.0'. But not working at my Phone (Android Pie 9.0).
Only I found that working is 'onGoing' Notification, but I need removable notification from service.
How can I do? I need your help. Thank you for reading my question.
ADDED CODE
nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
tabletnoti_channel = new NotificationChannel(TABLETNOTI_ID, getString(R.string.noti), NotificationManager.IMPORTANCE_DEFAULT);
tabletnoti_channel.setDescription(getString(R.string.app_name));
tabletnoti_channel.enableLights(true);
tabletnoti_channel.setLightColor(ContextCompat.getColor(getApplicationContext(), R.color.colorPrimary));
tabletnoti_channel.enableVibration(true);
tabletnoti_channel.setVibrationPattern(new long[]{100, 200, 100, 200});
tabletnoti_channel.setLockscreenVisibility(Notification.VISIBILITY_PRIVATE);
nm.createNotificationChannel(tabletnoti_channel);
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
Statebuilder = new Notification.Builder(getApplicationContext(), TABLETNOTI_ID);
} else {
Statebuilder = new Notification.Builder(getApplicationContext());
}
StateBuilder.setContentTitle(sharedPreferences.getString("connectDevice", "sample") + " " + getString(R.string.device_bat))
.setContentText(getString(R.string.not_connected))
.setOngoing(true)
.setShowWhen(false)
.setColor(ContextCompat.getColor(getApplicationContext(), R.color.colorPrimary))
.setSmallIcon(R.drawable.ic_cloud_off)
.setOnlyAlertOnce(true);
if (sharedPreferences.getBoolean("show_noti", true)) nm.notify(STATE_NOTI_ID, StateBuilder.build());
else nm.cancel(STATE_NOTI_ID);