0

When sending pre-filled SMS messages through Google's Web Share API, which lets users choose their app, there are a ton of options including Google Drive and Bluetooth. I want to limit these options to sms/ social media apps (Android Messages, Whatsapp, etc.)

So far my research has been inconclusive so I haven't made any headway in trying this out, this is also my first time trying to use these tools so go figure.

Here's the part of the function that contains the android sharing functionality;

    if (ver == undefined){ //not iOS
        if (device.isAndroid){
            if (navigator.share != undefined) //navigator.share pops up the app choice tray on device
            {
                navigator.share({
                    text: shareSMSMsg
                })
                .catch(err => console.error(err));
            }
            else{
                window.location.href = "sms:?body="+ androidEncode(shareSMSMsg); //if shareWebAPI feature isnt ll just try and use the default sms service
            }
        }
        else{
            window.location.href = "sms:?body="+ encode(shareSMSMsg);
        }
     }

Ideally it would limit the choices to just sms/messaging apps to make the experience a bit cleaner and open up less opportunity for user error.

2 Answers2

0

Check and see if it returns some sort of data. using: .then(( obj ) => console.log('Successful share' + JSON.Stringify(obj))) before the .catch

0

Per W3C specifications, no you can't limit/control the share targets/apps. See these sections:

https://www.w3.org/TR/web-share/#share-targets

https://www.w3.org/TR/web-share/#examples-of-share-targets

If you want to guide ("control") user behavior, I would show UI icons for each messaging app (that the user would then tap to share to the specific app), and then use the corresponding href protocol [if the app/target offers one]. For example with SMS like you are using now with 'sms:'. Then for WhatsApp, use something like 'https://wa.me/?text=urlencodedtext'. For WhatsApp, see https://faq.whatsapp.com/iphone/how-to-link-to-whatsapp-from-a-different-app/?lang=en and Sharing link on WhatsApp from mobile website (not application) for Android

csautot
  • 36
  • 6