After reading documentation + google remediation.

I still don't find a way to solve this problem.

My pending intent :

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()

Also I think redundant call to .setClass() is useless but I don't find what to do more. Also logcat output :

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)

Also I don't understand why he said action=null...

Thanks for help.

1

There are 1 best solutions below

1
Polarcode On

The warning indicates that your PendingIntent is mutable because its action is set to null. You have to comply with the new Android security requirements by setting the action explicitly when creating the PendingIntent.

You've set the action for the Intent like this

.setAction(lCtx.packageName + ".UpdateWIDGET")

The problem with this approach is that you are appending ".UpdateWIDGET" to the package name, and it might result in a mismatch in the action set for the Intent. As a result, the action is treated as null, leading to the warning message about a mutable implicit PendingIntent.

Try to replace it with

.setAction("com.example.yourappname.UpdateWIDGET")` 

note that the "com.example.yourappname" is your actual package name.

Also, the .setClass() is indeed redundant in your code. Since you are already setting the component using .setComponent(), you can now remove it.

e.g.

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

val updateIntent = Intent(lCtx, widgetClass)
                    .setComponent(componentName)
                    .setAction("com.example.yourappname.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()