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

Cannot share image using Facebook, WhatsApp or shareVia() function. #774

Open replysam2009 opened 7 years ago

replysam2009 commented 7 years ago

Hi, I am using Social Sharing plugin in one of my Ionic2 projects. Earlier everything was working fine but from past 3 days I am not being able to share anything using different share functions (except for shareViaMail()). Whenever I try to share anything it says: "Attempt to invoke virtual method 'android.content.res.XmlResourceParserandroid.content.pm.ProviderInfo.loadXmlMetaData(android.content.pm.PackageManager, java.lang.String)' on a null object reference." This happens only when I try to share image. If I share only message and Url, it works fine but if I try to share any image (by giving its url as a string), it throws an error. Is there anything you can help me with?

WilsonYHChan commented 7 years ago

hello, did you manage to share file ?

replysam2009 commented 7 years ago

No, I haven't tried. Let me try it now.

replysam2009 commented 7 years ago

Ok so I just tried to share a pdf file, except for Mail, every other sharing function failed. However, for twitter, the app got opened and only the message was shown (this was happening even when I was sharing a picture). I don't know why it is happening now. 3 days before I was able to share picture, url along with message on WhatsApp, Twitter, Facebook and GooglePlus but now I am getting error saying null reference (as written in the comment above)

replysam2009 commented 7 years ago

For your reference, following is my code: SocialSharing.shareViaWhatsApp('This is the message', 'https://www.google.co.in/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png', 'https://www.google.co.in') .then((data)=>{ alert("Success"); }, (err)=>{ alert(err); })

satriasss commented 7 years ago

UP UP

Hesesses commented 7 years ago

Did you find a solution for this? Sharing an image on fb / whatsapp?

WilsonYHChan commented 7 years ago

Hi,

i never try to share image on whatsapp, i just want to share pdf file to whatsappa, but it should be same as image. i have try few way just no luck and the whatsapp only show message only, no attachment.

i have post another issue after try for few day, below is my new post

https://github.com/EddyVerbruggen/SocialSharing-PhoneGap-Plugin/issues/856

On Wed, Jul 26, 2017 at 2:04 AM, Hesesses notifications@github.com wrote:

Did you find a solution for this? Sharing an image on fb / whatsapp?

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/EddyVerbruggen/SocialSharing-PhoneGap-Plugin/issues/774#issuecomment-317819069, or mute the thread https://github.com/notifications/unsubscribe-auth/AYgy5onFNF2NzDvKrc_W9mWoCbSo425Xks5sRi4egaJpZM4L-c03 .

mfdeveloper commented 6 years ago

Hello @replysam2009 !! I've got this same error. In my case, this is happened because the file sharing_paths.xml is missing. I'm running a Cordova app from a native app, and because this, the cordova [something]commands that create this file automatically, isn't a solution for me :(

To solve this, I did these things below:

Whether you need share a file with a custom extension (e.g file.myextension), create a cache file with a known extension (.txt, .doc, .png...) and share them, passing the real name + extension like subject param. This plugin contains a MIME_Map with allowed extensions and their mime types. To avoid this, I think that plugin needs a way to define custom extensions (e.g a custom xml tag in cordova config.xml, or a custom method called from JS...)

I hope that steps above help you :smile:

Juliocbr commented 5 years ago

Thanks @mfdeveloper your solution works great!!!

mfdeveloper commented 5 years ago

@Juliocbr We're welcome! I'm so glad that solution works to you :smiley:

RenewedPlains commented 5 years ago

I couldn't share media on Android (on iOS sharing worked fine). I constantly got the bug for the Android xml parser. After adding the code above in AndroidManifest.xml, this worked fine. thanks @mfdeveloper !!

`

`

ab-kily commented 5 years ago

Thanks to @mfdeveloper, I've implemented the same within config.xml:

    <platform name="android">
...
        <config-file parent="/manifest/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>
...
    </platform>
mfdeveloper commented 5 years ago

Hey @ab-kily and @RenewedPlains, these exatly same xml tags are present in plugin.xml#L86 file of this plugin. The cordova cli add these tags under <config-file> in AndroidManifest.xml automatically, when this plugin is added.

Did you try remove and add this plugin again? I need add these tags manually, because my project is an Android Native, with an Activity that loads a cordova app.

ahmedelatab commented 4 years ago

Thanks @mfdeveloper. Appreciated!

kapilSoni101 commented 3 years ago

@mfdeveloper: sir in my case files are already exist in the place that you have mentioned but still error i got Sharing failed please try again error only from whatsapp.can you tell me sir any another solution

mfdeveloper commented 3 years ago

Hy @kapilSoni101 !!

Did you try the solutions of @ab-kily to put the <config-file> in your config.xml file of your cordova project ?

kapilSoni101 commented 3 years ago

@mfdeveloper - yes sir it's already added