全屏意图不打开通知

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

我正在尝试通过通知显示全屏意图(在 Android 13 设备上运行)。通知已发送,但意图未打开。

我已经授予了所需的权限,我的清单内容如下:


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

<activity
    android:name=".RingActivity"
    android:exported="false"
    android:showOnLockScreen="true"
    android:turnScreenOn="true" />
<receiver android:name=".infrastructure.Receiver" />

这里是创建通知和全屏意图的相关代码:


private fun createChannel() {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        val importance = NotificationManager.IMPORTANCE_HIGH
        val channel = NotificationChannel("my_channel_id", "Alarm", importance)
        val notificationManager: NotificationManager =
            context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
        notificationManager.createNotificationChannel(channel)
    }
}

private fun notify(alarm:Alarm, intent:Intent){
    createChannel()
    val pendingIntent = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE)
    val builder = NotificationCompat.Builder(context, "my_channel_id")
        .setSmallIcon(android.R.drawable.arrow_up_float)
        .setContentTitle("title")
        .setContentText("description")
        .setPriority(NotificationCompat.PRIORITY_HIGH)
        .setContentIntent(pendingIntent)
        .setPriority(NotificationManager.IMPORTANCE_HIGH)
        .setFullScreenIntent(pendingIntent,true)
    if (ActivityCompat.checkSelfPermission(context, Manifest.permission.POST_NOTIFICATIONS) != PackageManager.PERMISSION_GRANTED
    ) return
    NotificationManagerCompat.from(context).notify(alarm.id,builder.build())
}

谁能帮我弄清楚为什么无法打开全屏意图?

*这是我试图打电话的意图:

val intent = Intent(context,RingActivity::class.java).also {
        it.flags = Intent.FLAG_ACTIVITY_NEW_TASK
        it.putExtra("id",alarm.id)
}
android kotlin android-notifications
© www.soinside.com 2019 - 2024. All rights reserved.