Is it possible to generate a 'share on Facebook' link that opens the native Facebook App on Android/iOS/mobile instead of the web share dialog?

AndroidIosFacebookMobile

Android Problem Overview


Is it possible to have a share on Facebook link on a website that opens the share dialog in the native App?

Current behavior:

Right now clicking the Facebook share link opens the web-based share dialog, which is bad since most mobile Facebook user are using the native app, thus are not logged in on their browsers. Consequently the web share dialog prompts them to input their user credentials - which might lead them to not share after all.

Ideal behavior:

Clicking the share on Facebook link leads to the share dialog in the native Facebook app, where the user is already signed in.

Thanks in advance for the help!

Android Solutions


Solution 1 - Android

As of now, there is no official way to achieve this. It could be implemented by Facebook though, forwarding their web share dialog using their custom URL scheme. So if you use the officially documented way to open this dialog you would get this functionality with no further changes as soon as it becomes available.

The easiest way to use the official web share dialog, without any prerequisites, is to link to this URL:

https://www.facebook.com/dialog/share?
    app_id=145634995501895
    &display=popup
    &href=URL_TO_SHARE
    &redirect_uri=RETURN_URL

where you replace URL_TO_SHARE and RETURN_URL with the proper URL-encoded values. Or you include the Facebook JS-SDK and use the classical share button or other ways described in sharing on the web.

Just for completeness: In native apps on iOS and Android it is possible to link to the Facebook app directly if the user has the Facebook app installed. See sharing from iOS or android. As this is not always the case you have to check using the respective platform's specific Facebook SDK and fallback to the web-based dialog as well.

On a sidenote: I would highly discourage you from using the not officially documented URL-schemes registered by the Facebook app. While they might work if the website is visited from a device with an installed Facebook app, they become dead links or weird browser warnings on devices without the Facebook app installed, especially any PCs or Macs. Even if you check for all these cases, Facebook has already changed their URL-Schemes and might do so again at any time, breaking your link(s) or - maybe worse - leading to undefined behavior.

Solution 2 - Android

https://developer.mozilla.org/en-US/docs/Web/API/Navigator/share

You could try this and let the user decide what native app to use when sharing your link.

It opens the native share-via of the user's device

const data = {
  title: document.title,
  text: 'Hello World',
  url: 'https://your_site_url',
}

const shareVia = window.navigator.share(data);
<html>
 <button onClick={shareVia}>Share Me!</button>
</html>

Solution 3 - Android

The following code will check if the app is installed, if installed you can share using the app, you don't have to open Facebook in your web browser and log in again. If the app is not installed it will simply use the Facebook sharer link then the user has to log in to Facebook in the browser if not logged in and the link gets shared.

  onShare() {
    console.log(order);
    const title = 'Title';
    const url = 'https://www.facebook.com/';
    const text = "Share on native app if installed";
    if (navigator.share) {
      navigator
        .share({ title: `${title}`, url: `${url}`,text: `${text}`})
        .then(() => {
          console.log('Thanks for sharing!');
        })
        .catch(console.error);
    } else {
      window.location.replace(
        `https://www.facebook.com/sharer.php?u=${url.trim()}&quote=${text}`
      );
    }
  } //onShare ends here

Solution 4 - Android

<a href="fb://page/100623981381289">
    This is My page (click on your Phone installed facebook)
</a>

Solution 5 - Android

I know it has been a couple of years, but for whom it may concern:
Have a look at this answer; https://stackoverflow.com/questions/31941188/xcode-sharing-content-via-action-sheet.

Let me copy that answer overhere as well:

Swift

let shareText = "Hello, world!"
if let image = UIImage(named: "myImage") {
    let vc = UIActivityViewController(activityItems: [shareText, image], applicationActivities: [])
    presentViewController(vc, animated: true, completion: nil)
}

Try links for tutorials

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionWalkerView Question on Stackoverflow
Solution 1 - Androidjan.vogtView Answer on Stackoverflow
Solution 2 - AndroidmonView Answer on Stackoverflow
Solution 3 - AndroidRohan Kumar ThakurView Answer on Stackoverflow
Solution 4 - AndroidHein SoeView Answer on Stackoverflow
Solution 5 - AndroidEndranView Answer on Stackoverflow