Facebook的Andr​​oid SDK和白色屏幕 [英] Facebook android SDK and white screen

查看:109
本文介绍了Facebook的Andr​​oid SDK和白色屏幕的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Facebook的Andr​​oid SDK中允许SSO。我按照说明书和Hackbook的教程,但它发生的手机似乎stucked一个白色的屏幕上,会出现一个进度对话框10秒后,过程继续按预期。

I am using Facebook Android SDK to allow SSO. I have followed the guide and the tutorial in Hackbook but it happens that the phone seems stucked on a white screen, after 10 seconds a progress dialog appears and the process continues as expected.

我试图努力解决这些问题(异步任务,透明的布局),但它似乎没有什么工作。

I have tried hard to fix the issue (async tasks, transparent layouts) but it seems nothing is working.

这是Facebook的活动code:

This is the code in facebook activity:

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.facebook_activity);
    /*
     * Get existing access_token if any
     */
    mPrefs = getPreferences(MODE_PRIVATE);
    String access_token = mPrefs.getString("access_token", null);
    long expires = mPrefs.getLong("access_expires", 0);
    if (access_token != null) {
        facebook.setAccessToken(access_token);
    }
    if (expires != 0) {
        facebook.setAccessExpires(expires);
    }

    /*
     * Only call authorize if the access_token has expired.
     */
    // showProgress();
    if (!facebook.isSessionValid()) {

        authorizeFacebook();
    } else {
        signalResult();
    }
}


private void authorizeFacebook() {
    facebook.authorize(this, new String[] { "email", "offline_access",
            "publish_stream", "user_about_me" }, new DialogListener() {
        @Override
        public void onComplete(Bundle values) {
            // SharedPreferences.Editor editor = mPrefs.edit();
            // editor.putString("access_token",
            // facebook.getAccessToken());
            // editor.putLong("access_expires",
            // facebook.getAccessExpires());
            // editor.commit();
            signalResult();
            // retrieve call obtain information and register

        }

        @Override
        public void onFacebookError(FacebookError error) {
        }

        @Override
        public void onError(DialogError e) {
        }

        @Override
        public void onCancel() {
        }
    });
}

private void signalResult() {
    // retrieve user info
    new AsyncFacebookRunner(facebook).request("me",
            new AsyncFacebookRunner.RequestListener() {

                @Override
                public void onMalformedURLException(
                        MalformedURLException e, Object state) {
                    authorizeFacebook();
                }

                @Override
                public void onIOException(IOException e, Object state) {
                    authorizeFacebook();
                }

                @Override
                public void onFileNotFoundException(
                        FileNotFoundException e, Object state) {
                    authorizeFacebook();
                }

                @Override
                public void onFacebookError(FacebookError e, Object state) {
                    authorizeFacebook();
                }

                @Override
                public void onComplete(String response, Object state) {
                    Intent intent = new Intent();
                    String accessToken = facebook.getAccessToken();
                    String id = null;
                    JSONObject json;
                    try {
                        json = new JSONObject(response);
                        id = json.getString("id");
                        intent.putExtra(WeOrderApplication.FACEBOOK_USER, id);
                        intent.putExtra(WeOrderApplication.FACEBOOK,
                                accessToken);
                        // hideProgress();
                        setResult(RESULT_OK, intent);
                        finish();
                    } catch (JSONException e) {
                        authorizeFacebook();
                        e.printStackTrace();
                    }

                }
            });

}

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    facebook.authorizeCallback(requestCode, resultCode, data);
}

和它通过一个简单的StartActivity调用。 facebook_activity是在没有任何东西一个LinearLayout中。我已成立一个半透明的主题。(机器人:主题=@安卓风格/ Theme.Translucent.NoTitleBar),以FacebookActivity,使其至少透明的,但它也不能工作。

and it is called through a simple StartActivity. facebook_activity is a linearLayout without anything in it. I have set a translucent theme (android:theme="@android:style/Theme.Translucent.NoTitleBar") to FacebookActivity to make it at least transparent but it didn't work either.

由于任何人可以帮助解决这个。

Thanks to anyone that could help fixing this.

推荐答案

请在下方更新您authorizeFacebook()函数的code,它会解决你的问题。

Please update below code of your authorizeFacebook() function, it will solve your problem.

facebook.authorize(mActivity, mPermissions, Facebook.FORCE_DIALOG_AUTH,
            new LoginDialogListener());

和见下面的链接了解更多信息。

And see below link for more information.

<一个href=\"http://stackoverflow.com/questions/10815813/android-facebook-authorization-can-not-login-when-official-facebook-app-instal/10816381#10816381\">Facebook登录问题

这篇关于Facebook的Andr​​oid SDK和白色屏幕的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆