当设备使用 PIN/密码锁定时,全屏意图活动不会显示在外观屏幕上

Myr*_*ria 6 android fullscreen lockscreen android-notifications keyguard

我想在用户锁定设备后立即在 Android 外观屏幕上显示一份简短的调查问卷。为此,我检测屏幕锁定事件并显示带有全屏意图通知的活动。

 val fullScreenIntent = Intent(context, destination)
        fullScreenIntent.flags = Intent.FLAG_ACTIVITY_NO_HISTORY or
            Intent.FLAG_ACTIVITY_CLEAR_TASK or
            Intent.FLAG_ACTIVITY_CLEAR_TOP or
            Intent.FLAG_ACTIVITY_NEW_TASK

        val fullScreenPendingIntent = PendingIntent.getActivity(context, 0, fullScreenIntent, PendingIntent.FLAG_IMMUTABLE or PendingIntent.FLAG_UPDATE_CURRENT)

        val builder = NotificationCompat.Builder(context, CHANNEL_ID)
            .setSmallIcon(R.drawable.ic_logo)
            .setContentTitle(title)
            .setContentText(description)
            .setFullScreenIntent(fullScreenPendingIntent, true)
            .setPriority(NotificationCompat.PRIORITY_HIGH)
            .setCategory(NotificationCompat.CATEGORY_ALARM)

        with(notificationManager){
            createNotificationChannel()
            val notification = builder.build()
            notify(NOTIFICATION_ID, notification)
        }
Run Code Online (Sandbox Code Playgroud)

为了让活动显示在外观屏幕上,我在OnCreate调查问卷活动的方法中执行此操作:

fun Activity.turnScreenOnAndKeyguardOff() {
    setShowWhenLocked(true)
    setTurnScreenOn(true)

    with(getSystemService(Context.KEYGUARD_SERVICE) as KeyguardManager) {
        requestDismissKeyguard(this@turnScreenOnAndKeyguardOff, null)
    }
}
Run Code Online (Sandbox Code Playgroud)

在清单中:

 <activity
        android:name="com.example.trackingapp.activity.LockActivity"
        android:exported="true"
        android:launchMode="singleTop"
        android:showOnLockScreen="true"
        android:excludeFromRecents="true"/>
Run Code Online (Sandbox Code Playgroud)

这适用于 Android 9、10 和 11 以及某些 Android 12 (Pixel 3) 设备。但在某些 Android 12 设备上(我已在 Samsung A42 和 Pixel 4 上进行了测试),当设备配置了 PIN 或密码时,仅显示 PIN 键盘保护覆盖层。如果用户输入 PIN 码,设备就会解锁并且不会显示任何活动。

我也尝试过

 fun Activity.turnScreenOnAndKeyguardOff() {
    setShowWhenLocked(true)
    setTurnScreenOn(true)
 }
 
Run Code Online (Sandbox Code Playgroud)

但随后只有屏幕亮起。据我通过调试所看到的,活动的通知已创建,但立即自行完成。

有谁知道如何使用 PIN 码可靠地在锁定屏幕上显示活动,或者问题可能是什么?

提前致谢。