Facebookログイン(SSOが有効になっている)に接続されているAndroidアプリにログインすると、ログイン資格情報を入力しなくても、自動的にアプリにログインします。これが私のコードです。理由がわかりません。なぜこれがアプリで起こっているのか
package ten.mob.socialapp;
import java.io.IOException;
import java.net.MalformedURLException;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.os.StrictMode;
import com.facebook.android.AsyncFacebookRunner;
import com.facebook.android.DialogError;
import com.facebook.android.Facebook;
import com.facebook.android.Facebook.DialogListener;
import com.facebook.android.FacebookError;
public class FoodStarLoginActivity extends Activity{
private static final String faceBookAppId = "430255993683523";
static Facebook facebook = new Facebook(faceBookAppId);
private SharedPreferences mPrefs;
AsyncFacebookRunner asyncRunner;
Context context;
String logout = null;
@Override
public void onCreate(Bundle savedInstanceState){
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mPrefs = getPreferences(MODE_PRIVATE);
String access_token = mPrefs.getString("access_token", null);
long expires = mPrefs.getLong("access_expires", 0);
if(access_token != null){
facebook.setAccessToken(access_token);
}
if(expires != 0){
facebook.setAccessExpires(expires);
}
if(!facebook.isSessionValid()){
logInAuthorization();
}
Intent getintent = getIntent();
logout=getintent.getStringExtra("logout");
if(logout == null && facebook.isSessionValid()){
startSearchMyActivity();
}else{
facebookLogout();
if(!facebook.isSessionValid()){
logInAuthorization();
if(facebook.isSessionValid())
startSearchMyActivity();
}
}
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data){
super.onActivityResult(requestCode, resultCode, data);
facebook.authorizeCallback(requestCode, resultCode, data);
}
private void facebookLogout() {
try{
facebook.logout(getApplicationContext());
}catch(MalformedURLException e){
e.printStackTrace();
}catch(IOException e){
e.printStackTrace();
}
}
private void startSearchMyActivity() {
Intent intent = new Intent(this,SearchMyActivity.class);
startActivity(intent);
}
private void logInAuthorization(){
facebook.authorize(this, new DialogListener(){
@Override
public void onComplete(Bundle values){
SharedPreferences.Editor editor = mPrefs.edit();
editor.putString("access_token", facebook.getAccessToken());
editor.putLong("access_expires", facebook.getAccessExpires());
editor.commit();
}
@Override
public void onFacebookError(FacebookError error){}
@Override
public void onError(DialogError e){}
@Override
public void onCancel(){}
});
}
}