EddyVerbruggen / SocialSharing-PhoneGap-Plugin

👨‍❤️‍💋‍👨 Cordova plugin to share text, a file (image/PDF/..), or a URL (or all three) via the native sharing widget
MIT License
1.78k stars 905 forks source link

app crash on share #1185

Open BootsBack opened 1 year ago

BootsBack commented 1 year ago

Android 12 API Level 31 my app crash on click <\button onclick="window.plugins.socialsharing.share(null, 'Android filename', 'data:image/png;base64,R0lGODlhDAAMALMBAP8AAP///wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACH5BAUKAAEALAAAAAAMAAwAQAQZMMhJK7iY4p3nlZ8XgmNlnibXdVqolmhcRQA7', null)">base64 image only<\/button>

pedropamn commented 1 year ago

Maybe because it's a base64 image... If you use Android Studio, can you paste what logcat says?

BootsBack commented 1 year ago

line 274: final PendingIntent pendingIntent = PendingIntent.getBroadcast(cordova.getActivity().getApplicationContext(), 0, receiverIntent, PendingIntent.FLAG_UPDATE_CURRENT);

change with this:

if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.S) { pendingIntent = PendingIntent.getBroadcast(cordova.getActivity().getApplicationContext(), 0, receiverIntent, PendingIntent.FLAG_IMMUTABLE); } else { pendingIntent = PendingIntent.getBroadcast(cordova.getActivity().getApplicationContext(), 0, receiverIntent, PendingIntent.FLAG_UPDATE_CURRENT); }

      Full code check attach file

SocialSharing.java.txt

merbin2012 commented 1 year ago

line 274: final PendingIntent pendingIntent = PendingIntent.getBroadcast(cordova.getActivity().getApplicationContext(), 0, receiverIntent, PendingIntent.FLAG_UPDATE_CURRENT);

change with this:

if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.S) { pendingIntent = PendingIntent.getBroadcast(cordova.getActivity().getApplicationContext(), 0, receiverIntent, PendingIntent.FLAG_IMMUTABLE); } else { pendingIntent = PendingIntent.getBroadcast(cordova.getActivity().getApplicationContext(), 0, receiverIntent, PendingIntent.FLAG_UPDATE_CURRENT); }

      Full code check attach file

SocialSharing.java.txt

You are awesome. Thank you very much it is working in Android 12 and the lower versions.

herman-nieuwoudt-specno commented 1 year ago

It is in the SocialSharing.java.txt, but you also have to change the pendingIntent.getIntentSender() to finalPendingIntent.getIntentSender()). This is in line 377 or 385

chooseIntent = Intent.createChooser(sendIntent, chooserTitle, finalPendingIntent.getIntentSender());

danieldanielecki commented 1 year ago

For those with an error if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.S) {^ symbol: variable S Cannot resolve symbol 'S' :301 increase the compileSdkVersion to 31, source: https://stackoverflow.com/questions/65044161/build-failed-error-cannot-find-symbol-if-build-version-sdk-int-build-versio (For me 29 was causing issues).