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?
How do I show activity on Lock screen instead of notification? To enable it you have to go to the app configuration -> Other permissions -> Show On Lock screen. The full screen activity will also not appear if you have an existing notification with the same id that has not been dismissed.
The interface used to describe a full-screen action for a notification. By setting a fullScreenAction , when the notification is displayed, it will launch a full-screen intent.
In Android 10 we need to add permission for USE_FULL_SCREEN_INTENT
Permissions changes for fullscreen intents
Apps that target Android 10 or higher and use notifications with fullscreen intents must request the USE_FULL_SCREEN_INTENT
permission in their app's manifest file.
This is a normal permission, so the system automatically grants it to the requesting app.
Make sure you have added permission in manifest file
SAMPLE CODE
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.nilu.demo">
<uses-permission android:name="android.permission.USE_FULL_SCREEN_INTENT" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With