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

window.plugins.socialsharing.shareWithOptions failed to sent pdf in Whatapps #856

Open WilsonYHChan opened 7 years ago

WilsonYHChan commented 7 years ago

Hi, i am using Android phone and manage to use window.plugins.socialsharing.shareViaEmail to sent email together with the attachment as below:

window.plugins.socialsharing.shareViaEmail( 'Document sent from Testing', 'Test Subject AAA', ['abcd@gmail.com'], null, // CC: must be null or an array null, // BCC: must be null or an array ['file:///storage/MicroSD/Download/testAttach.pdf'], null, null ); *** if i remove one slash in file:///xxx become file://xxx , the attachemnt will not able to attach in the email.

my problem is when i try to use window.plugins.socialsharing.shareWithOptions as below, the attachment cannot attach into whatapps, only message appear in whatapps. i have try to set the option as

files: pdfBase64String, or
files: 'file:///storage/MicroSD/Download/testAttach.pdf',

the attachment is missing but no error. if i change it to

files: [pdfBase64String], or
files: ['file:///storage/MicroSD/Download/testAttach.pdf'], below error occur:

Sharing failed with message: Attempt to invoke virtual method 'android.....' on a null object reference

            var pdfBase64String = 'data:application/pdf;df:myOwnName.pdf;base64,' + 'jkAAABccaj..';
            try {
                var options = {
                    message: 'Document sent from Testing',
                    subject: 'Hi, i am email subject here', 
                    files: pdfBase64String, 
                    chooserTitle: 'Pick an app and share' 
                }
                var onSuccess = function (result) {
                }
                var onError = function (msg) {
                }
                window.plugins.socialsharing.shareWithOptions(options, onSuccess, onError);
            }
            catch (err) {
                alert(err.message);
            }

Any idea what is the probelm ???

Thanks.

mfdeveloper commented 6 years ago

@WilsonYHChan I've got the same problem using window.plugins.socialsharing.share() method. Did you resolve this? @EddyVerbruggen, can you help us ? Please!! :sweat_smile:

EddyVerbruggen commented 6 years ago

No time. But PR’s are accepted as always.

mfdeveloper commented 6 years ago

Hey @WilsonYHChan @EddyVerbruggen, I found a solution for whatsapp:

For some reason, you can't pass message. If you pass message + files parameter, whatsapp ignores the files and share the text msg. This is strange, and I don't know why, but it works!

So, the code to share for any app, is:

window.plugins.socialsharing.share(null | "", "My subject", ["native/path/of/myfile.extension"]);

Only for whatsapp:

window.plugins.socialsharing.shareViaWhatsApp(null | "", ["native/path/of/myfile.extension"]);
Ajay-kumar-abacus commented 2 months ago

is there any way to send both text and attachment same time