我可以在来电和屏幕解锁时显示重定向到通话活动的通知,但是当屏幕锁定处于活动状态时该通知没有响应。我看到了,但如果我点击它,则不会触发任何事件。
我使用来自 https://developer.android.com/training/notify-user/time-sensitive
的以下代码val fullScreenIntent = Intent(this, CallActivity::class.java)
fullScreenIntent.flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_NO_USER_ACTION or Intent.FLAG_ACTIVITY_SINGLE_TOP
val fullScreenPendingIntent = PendingIntent.getActivity(
this, 0,
fullScreenIntent, PendingIntent.FLAG_UPDATE_CURRENT
)
val notificationBuilder =
NotificationCompat.Builder(this, CHANNEL_ID)
.setSmallIcon(R.drawable.icon)
.setContentTitle("Incoming call")
.setContentText("(919) 555-1234")
.setPriority(NotificationCompat.PRIORITY_HIGH)
.setCategory(NotificationCompat.CATEGORY_CALL)
.setContentIntent(fullScreenPendingIntent)
.setFullScreenIntent(fullScreenPendingIntent, true)
val incomingCallNotification = notificationBuilder.build()
startForeground(NOTIFICATION_ID, incomingCallNotification)
已添加权限:
<uses-permission android:name="android.permission.USE_FULL_SCREEN_INTENT" />
我已经尝试了很多关于 SO 的建议,但似乎都没有奏效。我的活动确实需要代码才能在锁定屏幕上方打开,但它是从锁定屏幕调用的 onCreate 或 onNewIntent newer。
有什么想法吗?