Gok*_*oku 8 android android-notifications android-10.0
我正在使用全屏通知我的代码在Oreo版本中和以下版本中工作但是当我运行时android-Q我遇到了异常
Use of fullScreenIntent requires the USE_FULL_SCREEN_INTENT permission
Run Code Online (Sandbox Code Playgroud)
我正在使用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());
Run Code Online (Sandbox Code Playgroud)
Gok*_*oku 13
这是答案
现在我们需要<uses-permission android:name="android.permission.USE_FULL_SCREEN_INTENT" />在清单文件中添加权限
面向 Android Q 或更高版本并使用全屏 Intent 通知USE_FULL_SCREEN_INTENT的应用必须在其应用的清单文件中请求权限。这是一个正常的权限,因此系统会自动授予请求的应用程序
示例代码
<?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>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5667 次 |
| 最近记录: |