Android - Facebook共享内容被覆盖

时间:2015-06-09 22:09:34

标签: android facebook

这是我在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);

当网址是某个随机网站(例如developers.facebook.com)时,这很有用,但当它链接到Google Play时,内容标题和内容说明会被覆盖 - 标题会被标题覆盖Play商店和内容说明为空白。

那么如何链接到Play商店的应用程序,但保留自定义标题和说明?我知道这是可能的,因为我已经看过其他应用程序这样做了:

enter image description here

2 个答案:

答案 0 :(得分:4)

带有this链接的Facebook bug report帖子重复,其中Facebook确认了该行为并声明他们可能无法解决此问题。

至于其他应用程序如何获得这种行为,我猜错了。

如果您的应用程序有一个可以添加虚拟页面的网站,那么您可以执行以下操作:

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

然后对setContentUrl(Uri.parse("https://example.com/android")使用ShareDialog,其中网址会打开一个提供上述HTML的网页。

这会在用户打开该页面时自动将用户发送到您的Google Play商店页面。后退按钮仍然可以像直接进入Google Play商店页面那样工作。

我尝试使用HTTP重定向而不是实际上必须托管页面,但这不起作用。

编辑:您可以在页眉中加入AppLinks元标记,以跳过Android设备上的重定向。

<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向您展示如何处理应用中的链接。

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

如果该应用未安装在设备上,那么您将被发送到Google Play商店(虽然通过一个非常难看的弹出窗口,当直接使用Play商店链接时,在正常的ShareDialog流程中不会发生这种情况。)< / p>

此外,Facebook will create and host the page for you如果你想要的话。上面的示例HTML来自其中一个托管页面(请注意重定向的不同实现)。

答案 1 :(得分:3)

您可以使用深层链接方法来实现这一目标。 您只需要创建一个html页面并将所有商店链接(Google Play,App Store)放入元标记中并尝试共享该链接。您将能够实现您想要的效果,如果用户在Android上打开应用程序,他/她将被重定向到Google Play,如果用户在iOS上打开应用程序,他/她将被重定向到App Store页面。