I try to launch activity for a broadcastReceiver by using the next code
Intent i = new Intent(context, AlarmNotification.class);
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) { // This is at least android 10...
NotificationManager mgr = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
if (mgr.getNotificationChannel(CHANNEL_WHATEVER)==null) {
mgr.createNotificationChannel(new NotificationChannel(CHANNEL_WHATEVER,
"Whatever", NotificationManager.IMPORTANCE_HIGH));
}
mgr.notify(NOTIFY_ID, buildNormal(context, i).build());
}
private NotificationCompat.Builder buildNormal(Context context, Intent intent) {
NotificationCompat.Builder b=
new NotificationCompat.Builder(context, CHANNEL_WHATEVER);
b.setAutoCancel(true)
.setDefaults(Notification.DEFAULT_ALL)
.setSmallIcon(android.R.drawable.ic_lock_idle_alarm)
.setStyle(new NotificationCompat.BigTextStyle()
.bigText(TEXT)
.setContentText(TEXT)
.setFullScreenIntent(buildPendingIntent(context, intent), true);
return(b);
}
private PendingIntent buildPendingIntent(Context context, Intent intent) {
return(PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT));
}
In the beginning, everything work's perfectly fine. But if I enter the app settings, turn off the notification channel of CHANNEL_WHATEVER, and then turn it on again. Later when I call NotificationManager.notify it shows the notification in the notification drawer but does not start the activity. If I delete the app and reinstall, it works fine again. Is that a bug of android 10 which I should report on, or there is something I can do about it?
IMPORTANCE_HIGH
on that channel due to the disable/enable cycle. – Wrongdoingmgr.getNotificationChannel(CHANNEL_WHATEVER)
when it is notnull
. CallgetImportance()
and log what value you see. – Wrongdoing