Search code examples
androidcordovaphonegap-plugins

Can't share image from dataDirectory via SocialSharing-PhoneGap-Plugin


I have a Cordova android project and using SocialSharing-PhoneGap-Plugin to share images

I'm storing images in dataDirectory. But when sharing image, it won't shares!

window.plugins.socialsharing.share('', 'subject', window.cordova.file.dataDirectory + 'folder/image.jpg');

Share popup appears and I can select an app, subject will share but image won't!

If I share an image from www folder, it works fine.


Solution

  • I used share with image data method:

    window.plugins.socialsharing.share(null, 'Android filename', 'data:image/png;base64,R0lGODlhDAAMALMBAP8AAP///wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACH5BAUKAAEALAAAAAAMAAwAQAQZMMhJK7iY4p3nlZ8XgmNlnibXdVqolmhcRQA7', null);
    

    Note: passing a base64 file as 'data:' is not supported on Android 2.x

    You can see here how to Get base64 image data