我使用Facebook ShareDialog共享链接和照片,具体取决于内容。但是我看到一个奇怪的问题。当我点击我的shareActionProvider中的Facebook图标时,它首先用空白帖子打开ShareDialog。然后,当我点击返回到我的应用程序时,它会重新打开ShareDialog,并显示我想要显示的链接/照片内容。Android Facebook共享正在打开shareDialog两次
这是我用来分享的代码。
....
shareActionProvider.setOnShareTargetSelectedListener(new MyActionProvider.OnShareTargetSelectedListener() {
@Override
public boolean onShareTargetSelected(MyActionProvider source, Intent intent) {
// Recover selected application name for custom action handling
final String appName = intent.getComponent().getPackageName();
switch (appName) {
case "com.facebook.katana": // Facebook
ShareLinkContent content = new ShareLinkContent.Builder()
.setContentUrl(Uri.parse("https://developers.facebook.com"))
.setContentTitle("Check it out!")
.build();
shareDialog.show(content);
break;
....
}
有没有人见过这种行为?
谢谢!
我随信附上了我看到两个屏幕,以便我看到他们进来。
编辑
我添加更多我的代码。
我使用一个自定义ShareActionProvider
分享到FB(这是从Android源代码的精确复制,除了我重写setOnShareTargetSelectedListener
)
在我的活动onCreate
:
FacebookSdk.sdkInitialize(getApplicationContext());
callbackManager = CallbackManager.Factory.create();
shareDialog = new ShareDialog(this);
shareDialog.registerCallback(
callbackManager,
shareCallback);
当我设置我的ShareActionProvider
:
Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.setType("text/plain");
if (shareActionProvider != null) {
shareActionProvider.setShareIntent(shareIntent);
//... this is before the setOnShareTargetSelected call ....
comment out shareDialog.show(content);它仍然显示空白对话框? – charliebeckwith 2015-04-03 23:34:13
@Solarnum现在它只显示空白对话框。之后没有显示正确的一个。 – 2015-04-03 23:36:36
hooray!那是你的问题。 – charliebeckwith 2015-04-03 23:38:24