我正在开发一个旨在使用 Facebook 登录的 android 应用程序。用户将使用他们的 Facebook 凭据登录该应用程序。当未安装 Facebook for android 应用程序时一切正常。但是,当设备具有 Facebook for android 应用程序时安装后,该应用程序没有超出登录界面。我该如何纠正?任何帮助将不胜感激。谢谢。下面是登录活动的代码。
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
import com.facebook.*;
import com.facebook.model.*;
import com.facebook.Session;
public class MokoActivity extends Activity implements OnClickListener{
TextView create_account;
EditText name;
//private UiLifecycleHelper uiHelper;
private boolean isResumed=false;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
create_account=(TextView)findViewById(R.id.textView_createAccount);
name=(EditText)findViewById(R.id.editText_name);
create_account.setOnClickListener(this);
}
public void onClick(View v) {
// TODO Auto-generated method stub
switch(v.getId()){
case R.id.textView_createAccount:
String user_name=name.getText().toString();
if(user_name.length()<4){
Toast toast=Toast.makeText(MokoActivity.this,"Invalid Name",Toast.LENGTH_LONG);
toast.show();
}
else{
Session.openActiveSession(this, true,new Session.StatusCallback(){
public void call(Session session,SessionState state,Exception exception){
if(state.isOpened()){
Intent intent=new Intent(MokoActivity.this,HomeActivity.class);
intent.putExtra("username",name.getText().toString());
startActivity(intent);
}
}
});
}
break;
}
}
public void onResume(){
Session session=Session.getActiveSession();
if(session != null && (session.isOpened() || session.isClosed())){
onSessionStateChange(session, session.getState(), null);
}
super.onResume();
isResumed = true;
}
@Override
public void onPause() {
super.onPause();
isResumed = false;
}
@Override
public void onDestroy() {
super.onDestroy();
}
private void onSessionStateChange(Session session, SessionState state, Exception exception) {
if(isResumed){
if (state.isOpened()) {
Intent intent=new Intent(MokoActivity.this,HomeActivity.class);
intent.putExtra("username",name.getText().toString());
startActivity(intent);
}
else if (state.isClosed()) {
Toast toast=Toast.makeText(MokoActivity.this,"Logged out...",Toast.LENGTH_LONG);
toast.show();
}
}
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
Session.getActiveSession().onActivityResult(this, requestCode, resultCode, data);
}
}