我使用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