Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error socialsharing.share(...) Android 12 #1176

Open
jeanluck36 opened this issue May 27, 2022 · 16 comments
Open

Error socialsharing.share(...) Android 12 #1176

jeanluck36 opened this issue May 27, 2022 · 16 comments

Comments

@jeanluck36
Copy link

In Android 12 after trying to use method socialsharing.share(...) the application closes immediately, in android studio shows this error in the log:

java.lang.IllegalArgumentException: com.app-xxx: 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:375)
    at android.app.PendingIntent.getBroadcastAsUser(PendingIntent.java:645)
    at android.app.PendingIntent.getBroadcast(PendingIntent.java:632)
    at nl.xservices.plugins.SocialSharing$2.run(SocialSharing.java:274)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
    at java.lang.Thread.run(Thread.java:920)

To solve this I had to go to android folder in the plugin, find SocialSharing.java, and replace this line:

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

With this code
int pendingIntentValueFLAG = 0; if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.S) { pendingIntentValueFLAG = PendingIntent.FLAG_MUTABLE; } else { pendingIntentValueFLAG = PendingIntent.FLAG_UPDATE_CURRENT; } final PendingIntent pendingIntent = PendingIntent.getBroadcast(cordova.getActivity().getApplicationContext(), 0, receiverIntent, pendingIntentValueFLAG);

Cordova and plugin version:
"cordova": "11.0.0"
"cordova-android": "^10.1.2"
"cordova-plugin-x-socialsharing": "^6.0.3"

@jeanluck36 jeanluck36 changed the title Error share Android 12 Error socialsharing.share(...) Android 12 May 27, 2022
@sachithd
Copy link

great stuff. This resolved the issue. Please merge this code on the next release. Thanks

GloriaTM referenced this issue in GloriaTM/SocialSharing-PhoneGap-Plugin Jun 24, 2022
@dilo99
Copy link

dilo99 commented Jul 21, 2022

@jeanluck36 @sachithd ok, but the build with this plugin still fails receiving this error: android:exported needs to be explicitly specified for element <receiver#nl.xservices.plugins.ShareChooserPendingIntent>. Apps targeting Android 12 and higher are required to specify an explicit value for "android:exported" when the corresponding component has an intent filter defined.
so you have to add android:exported="true" or better for this plugin false value, manually on AndroidManifest.xml after adding this plugin...
to you the build works even without this change on android 12?

@synduit-jenkins
Copy link

@jeanluck36 @sachithd I am facing the same issue
#1176 (comment)
@dilo99 did you resolve this?

@sachithd
Copy link

sachithd commented Aug 3, 2022

In the plugin.xml file manually added
android:exported="true" to receiver element

<config-file target="AndroidManifest.xml" parent="/*/application"> <receiver android:name="nl.xservices.plugins.ShareChooserPendingIntent" android:enabled="true" android:exported="true"> <intent-filter> <action android:name="android.intent.action.SEND"/> </intent-filter> </receiver> </config-file>

@Syahrul
Copy link

Syahrul commented Aug 9, 2022

If you're upgrading to Capacitor 4, you may encounter this issue as I did.
As @sachithd guide above, to save people some time, the file is in node_modules/cordova-plugin-x-socialsharing/plugin.xml

@vchabal
Copy link

vchabal commented Aug 12, 2022

To anyone who got here recently:

@bonjourjoel
Copy link

I have the same error, and also the error about android:export=true.

The plugin seems dead. Is there any alternative with updates for the latest android?

mihir855 added a commit to mihir855/SocialSharing-PhoneGap-Plugin that referenced this issue Aug 20, 2022
@pedropamn
Copy link

In the plugin.xml file manually added android:exported="true" to receiver element

<config-file target="AndroidManifest.xml" parent="/*/application"> <receiver android:name="nl.xservices.plugins.ShareChooserPendingIntent" android:enabled="true" android:exported="true"> <intent-filter> <action android:name="android.intent.action.SEND"/> </intent-filter> </receiver> </config-file>

It fix the issue for you? For me, I can't even build. I'm still seeing the message:

Apps targeting Android 12 and higher are required to specify an explicit value for android:exported when the corresponding component has an intent filter defined. See https://developer.android.com/guide/topics/manifest/activity-element#exported for details

@EYALIN
Copy link

EYALIN commented Sep 1, 2022

@EddyVerbruggen can you please merge the pr for the solution for Android 12,13 ?

1 similar comment
@iamromec
Copy link

iamromec commented Sep 5, 2022

@EddyVerbruggen can you please merge the pr for the solution for Android 12,13 ?

@Topiya
Copy link

Topiya commented Sep 15, 2022

I am also facing the same issue.
Is there any solution for the same? Please let me know if it is available.

@EYALIN
Copy link

EYALIN commented Sep 15, 2022

@Topiya the fix was merged. please remove the plugin and add it again.

@Topiya
Copy link

Topiya commented Sep 15, 2022

Thanks for the reply.
but latest plugin install didn't solve the issue for me in "cordova-android": "^11.0.0"
I got the solution by using "cordova-plugin-x-socialsharing-android12"

@timonjagi
Copy link

Same case as @Topiya, seems like the latest plugin is still not adding android:exported to the manifest. I solved it by using the forked plugin cordova-plugin-x-socialsharing-android12

@EYALIN
Copy link

EYALIN commented Apr 12, 2023

@sachithd @Syahrul @timonjagi @vchabal @Topiya @pedropamn @bonjourjoel @jeanluck36
it has been fixed in my forked repo:
https://github.com/EYALIN/community-cordova-plugin-social-sharing

you can install it as an npm package:
cordova plugin add community-cordova-plugin-social-sharing --save

@mschoettle
Copy link

Does nl.xservices.plugins.ShareChooserPendingIntent actually have to be exported or could it be set to false?

I am getting the following for our app by the MobSF static analyzer:

Broadcast Receiver (nl.xservices.plugins.ShareChooserPendingIntent) is not Protected.
[android:exported=true]

A Broadcast Receiver is found to be shared with other apps on the device therefore leaving it accessible to any other application on the device.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests