Facebook SDK for Android - set Application ID programmatically

后端 未结 5 1147
逝去的感伤
逝去的感伤 2020-12-29 10:56

I have a native Android app that needs to connect to a different Facebook app (different Application ID) based on an app setting that can be changed at runtime.

Ima

5条回答
  •  别那么骄傲
    2020-12-29 11:34

    Here what i used to set the application id programatcally

        private Session.StatusCallback statusCallback = new SessionStatusCallback();
    
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    
        String s=""+R.string.app_id;
    
        Session session = new Session.Builder(getBaseContext()).setApplicationId(s).build();
    
        Session.setActiveSession(session);
    
        if (session.getState().equals(SessionState.CREATED_TOKEN_LOADED)) {
            session.openForRead(new Session.OpenRequest(this).setCallback(statusCallback));
        }
    }
    
    private class SessionStatusCallback implements Session.StatusCallback {
        @Override
        public void call(Session session, SessionState state, Exception exception) {
            // TODO Auto-generated method stub
            if(session.isOpened()){
                //Do your task
            }
        }
    }
    

提交回复
热议问题