这是我在 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);
当 URL 是某个随机站点(如 developer.facebook.com)时,这很有效,但当它是指向 Google Play 的链接时,内容标题和内容描述会被覆盖 - 标题会被 Play 商店中的标题覆盖内容描述为空白。
那么如何链接到 Play 商店中的应用程序但保留自定义标题和描述?我知道这是可能的,因为我已经看到其他应用程序这样做了:
最佳答案
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
,其中 url 会打开一个提供 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 流程中不会发生这种弹出窗口)。
此外,Facebook will create and host the page for you如果你想要那个。上面的示例 HTML 来自其托管页面之一(请注意重定向的不同实现)。
关于Android - Facebook 分享内容被覆盖,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30743698/