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

9
  • I believe this behavior is by design when sharing app store links, see this report.
    – ifaour
    Jun 15, 2015 at 11:35
  • So how do I override that behavior? I've seen other apps do it.
    – TimSim
    Jun 16, 2015 at 10:31
  • Maybe App Links might be useful for you.
    – ifaour
    Jun 16, 2015 at 12:00
  • you might want to use the shareApi Jun 16, 2015 at 16:46
  • 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.
    – mpkuth
    Jun 18, 2015 at 22:50

2 Answers 2

4
+75

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).

1
  • 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, 2015 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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.