android.app.StackTrace:新的可变隐式 PendingIntent:pkg=...、action=null、featureId=null。这将被阻止一次...pendingIntent错误

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

阅读文档 + google 修复后。

我还没有找到解决这个问题的方法。

我的待定意向:

val lCtx = context
val widgetClass = CrTWidgetReceiver::class.java
val componentName = ComponentName(lCtx, widgetClass)

val updateIntent = Intent(lCtx, widgetClass)
                    .setComponent(componentName)
                    .setClass(lCtx, widgetClass)
                    .setPackage(lCtx.packageName)
                    .setAction(lCtx.packageName + ".UpdateWIDGET")
    
val requestCode = widgetClass.name.hashCode()
val flags = PendingIntent.FLAG_CANCEL_CURRENT or PendingIntent.FLAG_IMMUTABLE

PendingIntent.getBroadcast(
    lCtx,
    requestCode, // Set a unique request code for the PendingIntent if needed
    updateIntent,
    flags
).send()

另外,我认为对

.setClass()
的多余调用是无用的,但我不知道还能做什么。 还有 logcat 输出:

android.app.StackTrace: New mutable implicit PendingIntent: pkg=..., action=null, featureId=null. This will be blocked once the app targets U+ for security reasons.
at android.app.PendingIntent.checkPendingIntent(PendingIntent.java:443)
at android.app.PendingIntent.getActivityAsUser(PendingIntent.java:544)
at android.app.PendingIntent.getActivity(PendingIntent.java:530)
at android.app.PendingIntent.getActivity(PendingIntent.java:494)

我也不明白他为什么这么说

action=null
...

感谢您的帮助。

android kotlin android-studio android-intent android-broadcast
© www.soinside.com 2019 - 2024. All rights reserved.