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

为何Full Screen Intent无法在锁屏状态下显示?

锁屏下来电全屏通知无法触发的问题排查与修复

问题现象

收到来电时,锁屏状态下仅触发振动,无法全屏展示CallActivity;解锁屏幕后通知栏显示常规通知,解锁状态下可正常显示悬浮通知。已尝试相关解决方案但未解决。

排查与修复方案

1. 通知渠道与权限确认

  • 确保USE_FULL_SCREEN_INTENT权限已在Manifest中声明,Android 13+需额外申请POST_NOTIFICATIONS权限;
  • 修正通知渠道创建代码,补全锁屏可见性配置,同时修复描述字段重复问题:
fun createIncomingCallChannel(
    context: Context,
    notificationManager: NotificationManagerCompat
) {
    val id = INCOMING_CALL_ID
    val name = context.getString(R.string.notification_channel_incoming_call_name)
    val description = context.getString(R.string.notification_channel_incoming_call_description) // 替换为正确的描述资源
    val channel = NotificationChannel(id, name, NotificationManager.IMPORTANCE_HIGH)
    channel.description = description
    channel.enableVibration(true)
    channel.enableLights(true)
    channel.setShowBadge(true)
    channel.lockscreenVisibility = Notification.VISIBILITY_PUBLIC // 明确设置锁屏可见性
    notificationManager.createNotificationChannel(channel)
}

2. PendingIntent与Intent Flags调整

  • 移除FLAG_ACTIVITY_NO_USER_ACTION标记(会阻止系统识别为用户交互启动),同时使用动态requestCode避免PendingIntent复用冲突:
val incomingCallNotificationIntent = Intent(context, CallActivity::class.java)
incomingCallNotificationIntent.addFlags(
    Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TOP
)
val pendingIntent = PendingIntent.getActivity(
    context,
    System.currentTimeMillis().toInt(), // 动态生成requestCode
    incomingCallNotificationIntent,
    PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE
)

3. Activity配置与代码优化

  • 在Manifest中为CallActivity配置独立任务栈与全屏主题,避免与主应用栈冲突:
<activity android:name=".ui.CallActivity"
    android:configChanges="orientation|screenSize|layoutDirection"
    android:theme="@style/FullScreenCallTheme" // 使用无状态栏的全屏主题
    android:launchMode="singleTask"
    android:turnScreenOn="true"
    android:showWhenLocked="true"
    android:excludeFromRecents="true"
    android:taskAffinity="" />
  • 修正CallActivity的onCreate逻辑,兼容更低版本的锁屏显示API:
override fun onCreate(savedInstanceState: Bundle?) {
    // 在super.onCreate前设置锁屏相关属性
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O_MR1) {
        setShowWhenLocked(true)
        setTurnScreenOn(true)
    } else {
        window.addFlags(
            WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED or
            WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON or
            WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD
        )
    }
    super.onCreate(savedInstanceState)
    
    // Android 10+ 申请解锁锁屏
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
        val keyguardManager = getSystemService(Context.KEYGUARD_SERVICE) as KeyguardManager
        keyguardManager.requestDismissKeyguard(this, object : KeyguardManager.KeyguardDismissCallback() {
            override fun onDismissError() {
                // 处理解锁失败逻辑
            }
            override fun onDismissSucceeded() {
                // 解锁成功后的操作
            }
        })
    }
}

4. 通知构建细节修正

  • 确保setFullScreenIntent优先级最高,移除可能冲突的setContentIntent(全屏Intent已包含跳转逻辑):
val builder = NotificationCompat.Builder(
    context,
    INCOMING_CALL_ID
)
    .setStyle(NotificationCompat.DecoratedCustomViewStyle())
    .addPerson(Person.Builder()
        .setName(displayName)
        .setKey(displayName)
        .build())
    .setSmallIcon(R.drawable.ic_stat_onesignal_default)
    .setContentTitle(displayName)
    .setContentText(context.getString(R.string.incoming_call_notification_title))
    .setCategory(NotificationCompat.CATEGORY_CALL)
    .setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
    .setPriority(NotificationCompat.PRIORITY_HIGH)
    .setWhen(System.currentTimeMillis())
    .setAutoCancel(false)
    .setShowWhen(true)
    .setOngoing(true)
    .addAction(notificationsManager.getCallDeclineAction(notifiable))
    .addAction(notificationsManager.getCallAnswerAction(notifiable))
    .setCustomHeadsUpContentView(notificationLayoutHeadsUp)
    .setFullScreenIntent(pendingIntent, true) // 确保此配置最后生效

额外注意事项

  • 部分国产ROM对全屏Intent有额外限制,需在系统设置中开启应用的“悬浮窗”“锁屏显示”权限;
  • 测试时需模拟应用后台/杀死状态下的来电场景,验证全屏效果;
  • Android 12+ 必须使用PendingIntent.FLAG_IMMUTABLE,避免兼容性崩溃。

内容的提问来源于stack exchange,提问作者osrl

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.03 10:32:37