Cordova-plugin-x-socialsharing not working

Is anyone else having issues with cordova-plugin-x-socialsharing or cordova-plugin-x-socialsharing-android12 plugins ?

window.plugins.socialsharing.shareWithOptions(options2, onSuccess, onError);

The onError function is called with error message:
Failed to connect to localhost/127.0.0:443

when I try to share a local file in TEMPORARY file location on Android (native).

This used to work but no longer does.

var options2 = {
           message: shareMsg,
           subject: shareTitle, 
           files: [source] 

shareMsg and shareTitle are varibles, it seems a file is actually sharing but instead of actually attaching the file referenced to by [source] it’s creating a new file with the contents of the file being the text of shareMsg

I cant determine if the bug is with cordova-plugin-x-socialsharing-android12 or cordova-plugin-file

This was all working fine in a previous build but on updating this app to fix an un-related bug (Chrome/WebView datalists), it no longer works.

Are your plug-in version numbers fixed or are you just grabbing whatever the latest is?

I havnt specified a version so it just grabs the latest version. I suspect it’s either cordova-plugin-x-socialsharing-android12 or cordova-plugin-file.

I do an sqlExport to a local file which i save to the TEMPORARY file location, then i get that file to share using cordova-plugin-x-socialsharing-android12.

I also do a similar method for a local PDF file which also throws the same error,

I’d hardcode the versions to the last release of the plug-in and test it.

Good idea, I’ll give it a go.

In the build log I’ve found this;

Discovered plugin "cordova-plugin-x-socialsharing-android12". Adding it to the project
Installing "cordova-plugin-x-socialsharing" for android

I have tried:

<plugin name="cordova-plugin-file" version="7.0.0" source="npm"/>
<plugin name="cordova-plugin-x-socialsharing-android12" version="6.0.4" source="npm" />

But still get the same error. I wonder if any permissions have changed in the latest version of Cordova/Android

Also the default Cordova splash screen is used rather than my own.

<engine name="android" spec="11.0.0" />
<preference name="AndroidWindowSplashScreenAnimatedIcon" value="www/images/android12Splash.png" />
<preference name="AndroidWindowSplashScreenAnimationDuration" value="2000"/>

Log: The “AndroidWindowSplashScreenAnimatedIcon” value does not exist. Cordova’s default will be used.

<platform name="android" >
  <preference name="AndroidXEnabled" value="true" />
  <preference name="AndroidPersistentFileLocation" value="Internal" />
  <preference name="android-minSdkVersion" value="21" />
  <preference name="android-targetSdkVersion" value="31" />

Solved: I had to add this to the config

<preference name="hostname" value="localhost" />
<preference name="AndroidInsecureFileModeEnabled" value="true" />

What are the repercussions of enabling the insecure file mode?

I wasn’t sure so I just looked it up: Config.xml - Apache Cordova

“If set to true loading file:/// URLs is allowed. Note: Enabling this setting allows malicious scripts loaded in a file:/// context to launch cross-site scripting attacks, either accessing arbitrary local files including WebView cookies, app private data or even credentials used on arbitrary web sites.”

I will try it again but only with <preference name="hostname" value="localhost" /> to see if that makes any difference.

Nope, error has returned by not using <preference name="AndroidInsecureFileModeEnabled" value="true" />

Any ideas on a work around so I don’t have to enable AndroidInsecureFileModeEnabled ?

Been awhile since I used the file plugin but I may have to circle back as I start allowing profile photo uploads in a new app. When I read the bug report on github it looked like there was an option using cdvfile:// that was safer. I’ll have to look later this weekend.

ok great, let me know how you get on. As this app is an urgent bug fix I may have to use AndroidInsecureFileModeEnabled untill another method is found.

Here’s an interesting thread on the Cordova site:

And another on Cordova’s DIscussions page: