你可以試試下面的代碼:
if(mFacebook.isSessionValid()) {
onFacebookClick();
}
private void onFacebookClick() {
if (mFacebook.isSessionValid()) {
final AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage("Delete current Facebook connection?")
.setCancelable(false)
.setPositiveButton("Yes",new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,int id) {
fbLogout();
}
})
.setNegativeButton("No",new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,int id) {
dialog.cancel();
facebook_btn.setText(getResources().getString(R.string.signinout));
}
});
final AlertDialog alert = builder.create();
alert.show();
} else {
facebook_btn.setText(getResources().getString(R.string.signin));
mFacebook.authorize(this, PERMISSIONS, -1,new FbLoginDialogListener());
}
}