错误:使用fullScreenIntent需要USE_FULL_SCREEN_INTENT权限

问题描述 投票:1回答:1

我正在使用全屏通知我的代码工作在Oreo及以下版本找到但是当我运行android-Q时我得到以下异常

Use of fullScreenIntent requires the USE_FULL_SCREEN_INTENT permission

我正在使用setFullScreenIntent()进行全屏通知

这是我的代码

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());
android android-notifications androidq
1个回答
1
投票

这是答案

现在我们需要在清单文件中添加<uses-permission android:name="android.permission.USE_FULL_SCREEN_INTENT" />权限

Permissions changes for fullscreen intents

针对Android Q或更高版本并使用全屏意图通知的应用必须在其应用的清单文件中请求USE_FULL_SCREEN_INTENT权限。这是一个normal permission,因此系统会自动将其授予请求的应用程序

示例代码

<?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>
© www.soinside.com 2019 - 2024. All rights reserved.