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 910 forks source link

Android social share to gmail fails #1026

Open worzella opened 5 years ago

worzella commented 5 years ago

Hello Eddy or anyone -

Running Cordova Android app on Android 9 phone and our logic creates a file on the local phone storage. We then try to use social sharing to allow the user to email this file. This used to work on Ionic1/AngularJS with older plugin version, but our current update of the app to Ionic 3 / Angular 4 sees this failing using 5.4.4 of the plugin.

We invoke the APi as such:

this.socialSharing.share(emailMsg_1, emailTitle_1, pathFile).then(function () { // Success! console.log("Shared log file by email - Success"); }).catch(function (error) { // Error! console.log("Shared log file by email - Error", error); });

But on Android (exact same code works fine on iOS app), it gets kicked out with this caught error object message:

Shared log file by email - Error Attempt to invoke virtual method 'android.content.res.XmlResourceParser android.content.pm.ProviderInfo.loadXmlMetaData(android.content.pm.PackageManager, java.lang.String)' on a null object reference

I have Googled like crazy but no working fixes. I strongly feel this is some sort of Android security issue preventing the Cordova app from passing files to another device app.

One more odd clue. My coworkers in Romania can build the same source code and they do not see this issue. But with all of the crazy levels and dependencies involved in Ionic/Cordova/Angular development, it could be one piece of the puzzle I have different.

I have done all the usual suggestions of deleting platform and re-adding and deleting plugin and re-adding.. nothing works.

Thanks - Randy

kprigel commented 5 years ago

This is what worked for me, as apparently the plugin.xml file was not getting merged correctly. In your config.xml file, add this:

    <edit-config file="AndroidManifest.xml" mode="merge" target="/manifest/application/provider">
        <provider android:authorities="${applicationId}.sharing.provider" android:exported="false" android:grantUriPermissions="true" android:name="nl.xservices.plugins.FileProvider">
            <meta-data android:name="android.support.FILE_PROVIDER_PATHS" android:resource="@xml/sharing_paths" />
        </provider>
    </edit-config>
worzella commented 5 years ago

Hi Eddy -

Thanks soooooooo much for the kind effort in helping. I will try it... in my last three weeks. My company Lenovo just laid off our whole team and my mobile career there is done. But I have good prospects at local companies in Ionic/Angular dev, so I will continue to use your fine plugins. Bravo! Randy

On Thursday, June 6, 2019, 2:16:03 PM EDT, kprigel <notifications@github.com> wrote:  

This is what worked for me, as apparently the plugin.xml file was not getting merged correctly. In your config.xml file, add this:

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or mute the thread.

danielrf121 commented 5 years ago

This is what worked for me, as apparently the plugin.xml file was not getting merged correctly. In your config.xml file, add this:

    <edit-config file="AndroidManifest.xml" mode="merge" target="/manifest/application/provider">
        <provider android:authorities="${applicationId}.sharing.provider" android:exported="false" android:grantUriPermissions="true" android:name="nl.xservices.plugins.FileProvider">
            <meta-data android:name="android.support.FILE_PROVIDER_PATHS" android:resource="@xml/sharing_paths" />
        </provider>
    </edit-config>

Thanks!

viking2917 commented 5 years ago

Had the same issue. The suggested workaround does allow Instagram to trigger for me, but now it opens to Instagram's direct message feature, rather than a feed post. (similar to: https://github.com/EddyVerbruggen/SocialSharing-PhoneGap-Plugin/issues/1043)

I think the AndroidManifest being incorrect is a symptom of a bigger and more annoying problem....I think this may be a side effect of a Cordova bug impacting correct generation of AndroidManifest.xml files (apache/cordova-common#89) (cf. https://github.com/phonegap/phonegap-plugin-push/issues/2850)

nvwebm commented 4 years ago

I tried the above solution, didn't work for me, and I get this error while adding the android platform

Unable to graft xml at selector "/manifest/application/provider" from "/home/nati/projects/adir_app/platforms/android/app/src/main/AndroidManifest.xml" during config install

I also tried this way:

    <config-file parent="application" target="AndroidManifest.xml">
            <provider android:authorities="${applicationId}.sharing.provider" android:exported="false" android:grantUriPermissions="true" android:name="nl.xservices.plugins.FileProvider">
                <meta-data android:name="android.support.FILE_PROVIDER_PATHS" android:resource="@xml/sharing_paths" />
            </provider>
        </config-file>

it works without error on release version but when I upload it to google play it give's the same error when sharing

vitto32 commented 4 years ago

@nvwebm did you solved the problem? Your solution (using config-file) works for me [1]. But I'm afraid to receive the same error on the google play.

[1] edit-config is meant for editing existing tags, but in my case the <provider> tag wasn't there

vitto32 commented 4 years ago

@EddyVerbruggen my guess is that in the config xml you should use parent="/*/application" or parent="application" instead of parent="/manifest/application". The <receiver> part is correctly added to the AndroidManifest while provider is not.

kotran88 commented 3 years ago

I tried the above solution, didn't work for me, and I get this error while adding the android platform

Unable to graft xml at selector "/manifest/application/provider" from "/home/nati/projects/adir_app/platforms/android/app/src/main/AndroidManifest.xml" during config install

I also tried this way:

    <config-file parent="application" target="AndroidManifest.xml">
            <provider android:authorities="${applicationId}.sharing.provider" android:exported="false" android:grantUriPermissions="true" android:name="nl.xservices.plugins.FileProvider">
                <meta-data android:name="android.support.FILE_PROVIDER_PATHS" android:resource="@xml/sharing_paths" />
            </provider>
        </config-file>

it works without error on release version but when I upload it to google play it give's the same error when sharing

having same issue...

worzella commented 3 years ago

HI - I haven't been on this project for 3 years, so sorry... I have no environment any more to check things out.  Good luck...  On Tuesday, February 2, 2021, 11:16:44 AM EST, kotran88 notifications@github.com wrote:

I tried the above solution, didn't work for me, and I get this error while adding the android platform

Unable to graft xml at selector "/manifest/application/provider" from "/home/nati/projects/adir_app/platforms/android/app/src/main/AndroidManifest.xml" during config install

I also tried this way:

it works without error on release version but when I upload it to google play it give's the same error when sharing

having same issue...

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or unsubscribe.

veronicatc commented 3 years ago

At plugin.xml, I moved this:

`

`

into the same config-file where the receiver code is.

And then it worked ok, when adding the plugin, it added the code to the Android Manifest.