Ad

Error : Use Of FullScreenIntent Requires The USE_FULL_SCREEN_INTENT Permission

I'm using notifications with fullscreen my code works find in Oreo and below version But when i'm running android-Q I'm getting below exception

Use of fullScreenIntent requires the USE_FULL_SCREEN_INTENT permission

I'm using setFullScreenIntent() for notifications with fullscreen

Here is my code

NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this, "123");

notificationBuilder.setAutoCancel(true)
            .setColor(ContextCompat.getColor(this, R.color.colorAccent))
            .setContentTitle(getString(R.string.app_name))
            .setContentText("Test")
            .setDefaults(Notification.DEFAULT_ALL)
            .setWhen(System.currentTimeMillis())
            .setFullScreenIntent(pendingIntent,true)
            .setSmallIcon(R.drawable.ic_launcher_background)
            .setAutoCancel(true);

mNotificationManager.notify(1000, notificationBuilder.build());
Ad

Answer

Here is the answer

Now wee need to add <uses-permission android:name="android.permission.USE_FULL_SCREEN_INTENT" /> permission in manifest file

Permissions changes for fullscreen intents

Apps that target Android Q 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

SAMPLE CODE

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="xxx.xxx.xxx">

    <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>
Ad
source: stackoverflow.com
Ad