【问题标题】:Use facebook share dialog without sending current activity to background使用 facebook 共享对话框而不将当前活动发送到后台
【发布时间】:2016-03-21 09:05:10
【问题描述】:

我正在使用谷歌游戏服务开发一款实时多人游戏,我想在我的应用中实现 Facebook 分享。我已经有照片共享工作,但谷歌游戏服务的工作方式是,如果游戏的活动进入后台,玩家离开房间,游戏就会断开连接。有没有办法使用 Facebook 在其 SDK 中提供的 ShareDialog 而无需将当前活动置于后台?我可以强制它半透明地覆盖吗?

我尝试过强制 FacebookActivity 像这样使用 Theme.Dialog 样式,但没有效果。

如果唯一的选择是创建我自己的自定义共享对话框,请提供一个示例,说明如何实现它并将我的 SharePhotoContent 传递给它。

<activity android:name="com.facebook.FacebookActivity"
        android:configChanges=
            "keyboard|keyboardHidden|screenLayout|screenSize|orientation"
        android:theme="@android:style/Theme.Dialog"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="transparent.text.FacebookActivity"/>
            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>

【问题讨论】:

    标签: android facebook


    【解决方案1】:

    您需要在您的应用程序中集成 facebook sdk。

    首先,在你的 onCreate 方法中创建一个 ShareDialog 实例。

    CallbackManager callbackManager;
    ShareDialog shareDialog;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        FacebookSdk.sdkInitialize(getApplicationContext());
        callbackManager = CallbackManager.Factory.create();
        shareDialog = new ShareDialog(this);
        // this part is optional
        shareDialog.registerCallback(callbackManager, new FacebookCallback < Sharer.Result > () {...
        });
    }
    

    然后使用下面的代码显示共享对话框。

    if (ShareDialog.canShow(ShareLinkContent.class)) {
        ShareLinkContent linkContent = new ShareLinkContent.Builder()
                .setContentTitle("Hello Facebook")
                .setContentDescription(
                        "The 'Hello Facebook' sample  showcases simple Facebook integration")
                .setContentUrl(Uri.parse("http://developers.facebook.com/android"))
                .build();
    
        shareDialog.show(linkContent);
    }
    

    还要处理 onActivityResult 中的回调。

    @Override
    protected void onActivityResult(final int requestCode, final int resultCode, final Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        callbackManager.onActivityResult(requestCode, resultCode, data);
    }
    

    【讨论】:

    • 嗯。我想也许我的问题不清楚。我已经完成了所有这些并且它正在工作,除了共享对话框本身迫使我的游戏进入后台,由于谷歌游戏服务的工作方式而破坏了它。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-01-03
    • 2016-07-01
    • 1970-01-01
    • 2014-08-07
    • 2018-06-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多