ionic-team / capacitor

Build cross-platform Native Progressive Web Apps for iOS, Android, and the Web ⚡️
https://capacitorjs.com
MIT License
12.34k stars 1.01k forks source link

bug: @capacitor/share PendingIntent IllegalArgumentException #5392

Closed BuffMcBigHuge closed 2 years ago

BuffMcBigHuge commented 2 years ago

Bug Report

Capacitor Version

@capacitor/cli: 3.4.0 @capacitor/core: 3.4.0 @capacitor/android: 3.4.0 @capacitor/ios: 3.4.0 @capacitor/share: 1.1.1

Platform(s)

Android

Current Behavior

Calling the share function Share.share({}) via import { Share } from '@capacitor/share'; crashes the Android app.

E/Capacitor: Serious error executing plugin
    java.lang.reflect.InvocationTargetException
        at java.lang.reflect.Method.invoke(Native Method)
        at com.getcapacitor.PluginHandle.invoke(PluginHandle.java:121)
        at com.getcapacitor.Bridge.lambda$callPluginMethod$0$com-getcapacitor-Bridge(Bridge.java:592)
        at com.getcapacitor.Bridge$$ExternalSyntheticLambda5.run(Unknown Source:8)
        at android.os.Handler.handleCallback(Handler.java:938)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loopOnce(Looper.java:226)
        at android.os.Looper.loop(Looper.java:313)
        at android.os.HandlerThread.run(HandlerThread.java:67)
     Caused by: java.lang.IllegalArgumentException: com.XXXX.XXXX: Targeting S+ (version 31 and above) requires that one of FLAG_IMMUTABLE or FLAG_MUTABLE be specified when creating a PendingIntent.
    Strongly consider using FLAG_IMMUTABLE, only use FLAG_MUTABLE if some functionality depends on the PendingIntent being mutable, e.g. if it needs to be used with inline replies or bubbles.
        at android.app.PendingIntent.checkFlags(PendingIntent.java:382)
        at android.app.PendingIntent.getBroadcastAsUser(PendingIntent.java:673)
        at android.app.PendingIntent.getBroadcast(PendingIntent.java:660)
        at com.capacitorjs.plugins.share.SharePlugin.share(SharePlugin.java:115)
            ... 9 more

Expected Behavior

It should not crash when target >= 31.

Code Reproduction

js:

Share.share({
    title: 'See cool stuff',
    text: 'Really awesome thing you need to see right meow',
    url: 'http://ionicframework.com/',
    dialogTitle: 'Share with buddies',
});

variables.gradle

targetSdkVersion = 31

Additional Context

https://developer.android.com/about/versions/12/behavior-changes-12 https://developer.android.com/reference/android/app/PendingIntent#FLAG_IMMUTABLE https://github.com/qiscus/qiscus-sdk-android/releases/tag/1.3.35

jcesarmobile commented 2 years ago

thanks for the issue, but it's already reported on the plugins repository https://github.com/ionic-team/capacitor-plugins/issues/690

capacitor will officially support to target SDK 31 on the next 4.0.0 release and plugins will also be updated to target SDK 31 and all the issues that targeting SDK 31 causes will be fixed.

BuffMcBigHuge commented 2 years ago

Ah didn't realize there was a separate issue section for plugins. Thanks 👍

nprather commented 2 years ago

Hi, I've run into this bug. Looks like compacitor 4.0 is in beta at the moment.

As a workaround until it's live, can you tell me where to set the "FLAG_IMMUTABLE or FLAG_MUTABLE be specified when creating a PendingIntent" ?

mirko77 commented 2 years ago

Same issue here

dgreasi commented 2 years ago

+1