19

This is my code to share the high score on Facebook:

ShareLinkContent content = new ShareLinkContent.Builder()
  .setImageUrl(Uri.parse("http://www.example.com/myicon.png"))
  .setContentTitle("I scored "+numPoints+" points!")
  .setContentUrl(Uri.parse("https://play.google.com/store/apps/details?id=com.my.package"))
  .setContentDescription("Get the game free on Google Play and beat my score.")        
  .build();
ShareDialog shareDialog = new ShareDialog(this);
shareDialog.show(content);

And this works great when the URL is some random site (like developers.facebook.com) but when it's a link to Google Play, the content title and content description get overwritten - title gets overwritten with the title from the Play store and content description is blank.

So how can link to the app on the Play store but keep the custom title and description? I know it's possible because I've seen other apps do it:

enter image description here

TimSim
  • 3,936
  • 7
  • 46
  • 83
  • I believe this behavior is by design when sharing app store links, see this [report](https://developers.facebook.com/bugs/1543859162514546/). – ifaour Jun 15 '15 at 11:35
  • So how do I override that behavior? I've seen other apps do it. – TimSim Jun 16 '15 at 10:31
  • Maybe [App Links](https://developers.facebook.com/docs/applinks) might be useful for you. – ifaour Jun 16 '15 at 12:00
  • you might want to use the shareApi – user2511882 Jun 16 '15 at 16:46
  • Duplicate of [this](http://stackoverflow.com/questions/30245720/google-play-url-messes-up-facebooks-share-dialog) post with a link to a [Facebook bug report](https://developers.facebook.com/bugs/1435972263375939) where Facebook confirms the behavior and states that they probably won't fix it. – mpkuth Jun 18 '15 at 22:50
  • Again, I've seen other apps doing it. There's a screenshot above and it links straight to the Play store without any intermediary/redirection. – TimSim Jun 19 '15 at 05:01
  • @TimSim - i had the same issue and looking at the bug report, i gave up. You mind telling which apps exhibit a different behavior? – user2511882 Jun 19 '15 at 17:05
  • maybe those apps are using an older version of the Facebook SDK – Leo supports Monica Cellio Jun 20 '15 at 02:44
  • @user2511882 There's a screenshot of one of the apps up there. The grey text where the link should be is custom but the link leads directly to Google Play without redirections. – TimSim Jun 20 '15 at 03:26

2 Answers2

4

Duplicate of this post with a link to a Facebook bug report where Facebook confirms the behavior and states that they probably won't fix it.

As for how other applications are getting that behavior, I have a guess.

If you're application has a website that you can add a dummy page to then you could do the following:

<html>
  <head>
    <script type="text/javascript">
      window.location.replace('https://play.google.com/store/apps/details?id=com.example.client');
    </script>
  </head>
  <body></body>
</html>

Then use setContentUrl(Uri.parse("https://example.com/android") for your ShareDialog where the url opens a page that serves the HTML above.

This will automatically send users to your Google Play Store page when they open that page. The back button should still work as if they went straight to the Google Play Store page as well.

I tried just using an HTTP redirect instead of actually having to host the page but that didn't work.


EDIT: You can include AppLinks meta tags in the page header to skip the redirect on Android devices.

<html>
<head><title>App Link</title>
    <meta property="fb:app_id" content="XXXXXXXXXXXXXXX"/>
    <meta property="al:ios:url" content="example://test"/>
    <meta property="al:ios:app_name" content="Example App"/>
    <meta property="al:ios:app_store_id" content="XXXXXXXXX"/>
    <meta property="al:android:package" content="com.example.client"/>
    <meta property="al:android:app_name" content="Example App"/>
    <meta property="al:android:url" content="example://test"/>
    <meta property="al:web:should_fallback" content="false"/>
    <meta http-equiv="refresh" content="0;url=http://play.google.com/store/apps/details?id=com.example.client"/>
</head>
<body>Redirecting...</body>
</html>

This shows you how to handle the link in your app.

<activity
    android:name="com.example.client.MainActivity"
    android:label="@string/app_name">

    <intent-filter>
        <action android:name="android.intent.action.MAIN"/>
        <category android:name="android.intent.category.LAUNCHER"/>
    </intent-filter>

    <intent-filter>
        <data android:scheme="example"/>
        <action android:name="android.intent.action.VIEW"/>
        <category android:name="android.intent.category.DEFAULT"/>
        <category android:name="android.intent.category.BROWSABLE"/>
    </intent-filter>

</activity>

If the app isn't installed on the device then you get sent to the Google Play Store (albeit through a very ugly popup which doesn't happen in the normal ShareDialog flow when a Play Store link is used directly).

Additionally, Facebook will create and host the page for you if you want that. The example HTML above is from one of their hosted pages (note the different implementation of the redirect).

Community
  • 1
  • 1
mpkuth
  • 6,994
  • 2
  • 27
  • 44
  • This does not work. The Android Facebook app just tries to open the URL in its own browser and what it opens is a page that says that Google Play doesn't support that browser. It should open the app's page in Google Play app but it doesn't. – TimSim Jun 27 '15 at 19:02
3

You can use deeplinking method to achieve that. All you have to is create a html page and put all store links(Google Play, App Store) in that a meta tag and try to share that link. You would be able to achieve what you want and also if the user opens the app on Android he/she will be redirected to Google Play and if the user opens the app on iOS he/she will be redirected to App Store page.

Rohit Goyal
  • 1,521
  • 3
  • 24
  • 49