Help with social share

Hello everybody!

I want to “share user stats” in my app. First, I do a screenshot, and then I want to share it with social share plugin…

This is my code:

public shareStats(): void {

        // Take a screenshot and get temporary file URI
        Screenshot.URI(100)
            .then((img) => {

                this.platform.ready().then(() => {

                    let message: string = 'Message';
                    let subject: string = 'Stats';
                    let file = img;
                    let link = 'https://www.example.com';

                    SocialSharing.share(message, subject, file, link);
                });

            }, (err) => {

                let prompt = this.alertCtrl.create({
                    title: 'Fallo',
                    subTitle: err,
                    buttons: ['Aceptar']
                });

                prompt.present();
                console.log(err);
            });
    }

Well, Screenshot plugin appears to work fine, but i don’t know what is happening after I added the social share code into it. Because my device do not open the tipically share options windows.

In short, I need to do screen capture and share this capture on social networks. But I do not know what I’m doing wrong because I can not debug it by being a cordova plugin and running only on mobile devices.

It makes me a bit of noise what I’m sending as a parameter: let file = img;
Because I do not know what it contains or what kind of data this img is that returns me Screenshot.URI, because I can not debug it with the mobile device.

Thank’s so much in advance!

Ivan.

I solved it:

public shareStats(): void {

        this.platform.ready().then(() => {
            // Take a screenshot and get temporary file URI
            Screenshot.URI(100)
                .then((res) => {

                    var options = {
                        message: this.SHARE_OPTIONS_MESSAGE,
                        subject: '', // fi. for email
                        files: [res.URI], // an array of filenames either locally or remotely
                        url: this.SHARE_OPTIONS_URL,
                        chooserTitle: this.SHARE_OPTIONS_CHOOSER_TITLE // Android only
                    }

                    SocialSharing.shareWithOptions(options)
                        .then(() => {
                            this.showSuccessShareMsg();
                        })
                        .catch((err) => {
                            this.showErrorShareMsg(err);
                        });

                }, (err) => {

                });
        });

    }
1 Like

And please, add to the docs how to manipule the Screenshot URI Response… people can’t guess that:

console.log(res.URI);

Thank’s

Greetings,
Were you able to identify to where the screenshot was shared?