Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Full screen intent not starting the activity but do show a notification on android 10

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?

like image 776
Simple UX Apps Avatar asked Sep 10 '19 10:09

Simple UX Apps


People also ask

How do I show activity on lock screen instead of notification?

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.

What is full screen intent notification?

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.


1 Answers

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>
like image 142
AskNilesh Avatar answered Oct 24 '22 11:10

AskNilesh