Android 13通知权限对话框出现在闪屏顶部

ruyhziif  于 2022-12-21  发布在  Android
关注(0)|答案(1)|浏览(237)

[here显示通知对话框在启动画面上打开,我想在其中自动显示,但用户enter image description here ere](https://i.stack.imgur.com/D2YJj.png)的流程不佳
我只添加了通知权限,它总是显示当用户第一次打开应用程序。

<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
eh57zj3b

eh57zj3b1#

将此代码添加到主Activity(而不是Splash Activity)中以获取权限。“@RequiresApi(Build.VERSION_CODES.TIRAMISU)

private fun getNotificationPermission() {
    if (ContextCompat.checkSelfPermission(
            this, android.Manifest.permission.POST_NOTIFICATIONS
        ) != PackageManager.PERMISSION_GRANTED
    ) {
        Log.e("TAG33", "getNotificationPermission: ", )
        shouldShowRequestPermissionRationale(android.Manifest.permission.POST_NOTIFICATIONS)
        requestPermissionLauncher.launch(
            Manifest.permission.POST_NOTIFICATIONS
        )
    }
}`

相关问题