我是android新手。我正在开发一个需要facebook登录才能继续的应用程序。所以为此,我遵循了本教程 - https://developers.facebook.com/docs/android/getting-started
编辑:使用UILifecycleHelper,一旦用户验证应用程序应用程序已关闭,同样的事情就会发生。
private Session.StatusCallback callback = new Session.StatusCallback() {
@Override
public void call(Session session, SessionState state, Exception exception) {
if (session.isOpened()) {
Log.w("Vinit", "Session started");
// make request to the /me API
Request.newMeRequest(session, new Request.GraphUserCallback() {
// callback after Graph API response with user object
@Override
public void onCompleted(GraphUser user, Response response) {
if (user != null) {
TextView t = (TextView) findViewById(R.id.textView1);
t.setText("User: " + user.getFirstName());
}
}
}).executeAsync();
}
}
};
private FacebookDialog.Callback dialogCallback = new FacebookDialog.Callback() {
@Override
public void onError(FacebookDialog.PendingCall pendingCall, Exception error, Bundle data) {
Log.d("HelloFacebook", String.format("Error: %s", error.toString()));
}
@Override
public void onComplete(FacebookDialog.PendingCall pendingCall, Bundle data) {
Log.d("HelloFacebook", "Success!");
}
};
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
if(new LoginChecker(this).isRegistered()){
Intent intent = new Intent(this, MainActivity.class);
startActivity(intent);
}else{
setContentView(R.layout.activity_login);
LoginButton loginButton = (LoginButton) findViewById(R.id.loginButton1);
thisActivity = this;
loginButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
uiHelper = new UiLifecycleHelper(thisActivity, callback);
}
});
}
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
Log.w("Vinit", "On Activity Result function");
uiHelper.onActivityResult(requestCode, resultCode, data, dialogCallback);
}
答案 0 :(得分:1)