You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Android 14请求通知权限时应用卡顿问题求助

Android 14请求通知权限时应用卡顿问题求助

各位大佬好,我正在开发一款Android应用,遇到了一个和Android 14(API level 34)相关的奇怪问题:首次启动应用时,我会触发通知权限的申请弹窗(对应权限为POST_NOTIFICATIONS),但不管用户选择允许还是拒绝这个权限,应用都会卡在启动页。只有将应用切换到后台再切回前台,登录页面才会正常显示出来。

以下是我在LoginActivity的onCreate()函数中调用的相关代码:

if (isFirstRun) {
   setupPushNotificationsChannel()

   if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
       // Check notifications permission
       if (ContextCompat.checkSelfPermission(
               this@LoginActivity,
               Manifest.permission.POST_NOTIFICATIONS
           ) == PackageManager.PERMISSION_DENIED
       ) {
           requestPermissions(
               arrayOf(Manifest.permission.POST_NOTIFICATIONS),
               REQUEST_POST_NOTIFICATION_CODE_PERMISSION
           )
       }
   }
   // Flip firstRun
   preferences.edit().putBoolean(FIRST_RUN_KEY, false).apply()
}


private fun setupPushNotificationsChannel() {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        // Create channel to show notifications.
        val channelId = getString(R.string.default_notification_channel_id)
        val channelName = getString(R.string.default_notification_channel_name)
        val notificationManager = getSystemService(NotificationManager::class.java)
        notificationManager?.createNotificationChannel(
            NotificationChannel(
                channelId,
                channelName,
                NotificationManager.IMPORTANCE_HIGH
            )
        )
    }
}

备注:内容来源于stack exchange,提问作者alexC

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.15 09:59:30