Android Facebook SDK不显示登录屏幕

时间:2013-10-13 02:09:35

标签: android facebook java-native-interface cocos2d-x facebook-android-sdk

我正在使用Cocos2dX我在一个名为login的自定义类中有一个方法,它由一些本机代码通过JNI调用,这是为了告诉Facebook登录并显示UI。但是,当我退出Facebook时,它没有显示任何内容。

public class AndroidFacebook {

    protected static Activity activity = null;
    protected static Context context = null;

    protected AndroidFacebook() {
        // Exists only to defeat instantiation.
    }

    public static void init(Activity activity) {
        AndroidFacebook.activity = activity;
        AndroidFacebook.context = activity.getApplicationContext();
    }

    @SuppressLint("ShowToast")
    public static void login() {

        Session.StatusCallback callback = new Session.StatusCallback() {

            public void call(Session session, SessionState state, Exception exception) {

            }
        };

        Session session = Session.getActiveSession();

        if (session == null) {
            session = new Session(AndroidFacebook.activity);
            Session.setActiveSession(session);
        }

        if (!session.isOpened() && !session.isClosed()) {
            session.openForRead(new Session.OpenRequest(AndroidFacebook.activity)
                .setPermissions(Arrays.asList("basic_info"))
                .setCallback(callback));
        } else {
            Session.openActiveSession(AndroidFacebook.activity, true, callback);
        }


    }

}

1 个答案:

答案 0 :(得分:1)

JNI调用在其单独的线程中,可能是您的c ++代码正在运行的线程。如果你想在android中控制UI,可以使用view.post或Activity.runOnUiThread来使其工作。