为什么锁屏上不显示全屏意图

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

我知道这个问题被问过很多次。我已经尝试了每个答案,但我找不到我的代码有什么问题。

我尝试在接到来电时显示通知。当收到推送通知时,我启动前台服务来监听来电。一段时间后,收到实际来电,并使用下面的代码显示通知。问题是,当手机锁定时,此通知应显示为全屏活动。相反,它只会振动。当我解锁屏幕时,我可以在通知托盘上看到正常的通知。如果手机解锁,我还可以看到抬头通知。

fun createIncomingCallChannel(
        context: Context,
        notificationManager: NotificationManagerCompat
    ) {
        // Create incoming calls notification channel
        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_name)
        val channel = NotificationChannel(id, name, NotificationManager.IMPORTANCE_HIGH)
        channel.description = description
        channel.enableVibration(true)
        channel.enableLights(true)
        channel.setShowBadge(true)
        notificationManager.createNotificationChannel(channel)
    }

fun createIncomingCallNotification(
        context: Context,
        notificationsManager: NotificationsManager
    ): Notification {
        val incomingCallNotificationIntent = Intent(context, CallActivity::class.java)
        incomingCallNotificationIntent.addFlags(
            Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_NO_USER_ACTION or Intent.FLAG_FROM_BACKGROUND
        )
        val pendingIntent = PendingIntent.getActivity(
            context,
            0,
            incomingCallNotificationIntent,
            PendingIntent.FLAG_CANCEL_CURRENT or PendingIntent.FLAG_IMMUTABLE
        )
        val displayName: String = "Foo"
        val address: String = "Bar"
        val info: String = "Incoming Call"

        val notificationLayoutHeadsUp = RemoteViews(
            context.packageName,
            R.layout.call_incoming_notification_heads_up
        )
        notificationLayoutHeadsUp.setTextViewText(R.id.caller, displayName)
        notificationLayoutHeadsUp.setTextViewText(R.id.sip_uri, address)
        notificationLayoutHeadsUp.setTextViewText(R.id.incoming_call_info, info)

        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)
            .setFullScreenIntent(pendingIntent, true)
            .addAction(notificationsManager.getCallDeclineAction(notifiable))
            .addAction(notificationsManager.getCallAnswerAction(notifiable))
            .setCustomHeadsUpContentView(notificationLayoutHeadsUp)
            .setContentIntent(pendingIntent)

        return builder.build()
    }

<uses-permission android:name="android.permission.USE_FULL_SCREEN_INTENT" />
...
<activity android:name=".ui.CallActivity"
            android:configChanges="orientation|screenSize|layoutDirection"
            android:theme="@style/Base.Theme.WhatsGo"
            android:launchMode="singleTask"
            android:turnScreenOn="true"
            android:showWhenLocked="true" />

CallActivity 的 onCreate:

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O_MR1) {
    setShowWhenLocked(true)
    setTurnScreenOn(true)

    val keyguardManager = getSystemService(Context.KEYGUARD_SERVICE) as KeyguardManager
    keyguardManager.requestDismissKeyguard(this, null)
}
super.onCreate(savedInstanceState)
android android-notifications android-pendingintent lockscreen
1个回答
0
投票

我发现在我的代码中的某个地方(确切地说是

getCallAnswerAction
)在创建待处理意图时,我无意中调用了
context.startActivity
。 (复制粘贴时发生)这不知何故导致全屏意图无法启动。

© www.soinside.com 2019 - 2024. All rights reserved.