Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android - Facebook share content gets overwritten

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

like image 932
TimSim Avatar asked Jun 09 '15 22:06

TimSim


2 Answers

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

like image 87
mpkuth Avatar answered Nov 17 '22 06:11

mpkuth


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.

like image 3
Rohit Goyal Avatar answered Nov 17 '22 07:11

Rohit Goyal