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

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

Open
replysam2009 opened this issue Feb 12, 2017 · 17 comments
Open

Comments

@replysam2009
Copy link

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
Copy link

hello, did you manage to share file ?

@replysam2009
Copy link
Author

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

@replysam2009
Copy link
Author

replysam2009 commented Feb 12, 2017

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
Copy link
Author

replysam2009 commented Feb 12, 2017

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
Copy link

UP UP

@Hesesses
Copy link

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

@WilsonYHChan
Copy link

WilsonYHChan commented Jul 26, 2017 via email

@mfdeveloper
Copy link

mfdeveloper commented Feb 28, 2018

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:

  • Make sure the file sharing_paths.xml exists on src/main/res/xml folder into your project (where the cordova webview is running)
  • Verifiy if the code snippet below is present in AndroidManifest.xml:

PS: This is necessary to create a temp folder to share files (images, txt...)

 <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>

Extra

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 😄

@Juliocbr
Copy link

Thanks @mfdeveloper your solution works great!!!

@mfdeveloper
Copy link

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

@RenewedPlains
Copy link

RenewedPlains commented Jun 11, 2019

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 !!

<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>

@ab-kily
Copy link

ab-kily commented Jul 25, 2019

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
Copy link

mfdeveloper commented Jul 26, 2019

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
Copy link

Thanks @mfdeveloper.
Appreciated!

@kapilSoni101
Copy link

@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
Copy link

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
Copy link

@mfdeveloper - yes sir it's already added

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

10 participants