此代碼運行良好當我卸載Facebook應用程序但未安裝Facebook應用程序。我正在使用Facebook SDK 4.0。Android應用程序與Facebook登錄未與Facebook應用程序安裝
這是我的代碼
package com.example.nhp04.gqfood;
import com.facebook.AccessToken;
import com.facebook.AccessTokenTracker;
import com.facebook.CallbackManager;
import com.facebook.FacebookCallback;
import com.facebook.FacebookException;
import com.facebook.FacebookSdk;
import com.facebook.Profile;
import com.facebook.login.LoginResult;
import com.facebook.login.widget.LoginButton;
public class Login extends AppCompatActivity implements Animation.AnimationListener {
private String info = "";
private LoginButton loginButton;
private CallbackManager callbackManager;
private AccessTokenTracker tracker;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
FacebookSdk.sdkInitialize(getApplicationContext());
callbackManager = CallbackManager.Factory.create();
setContentView(R.layout.activity_login);
loginButton = (LoginButton)findViewById(R.id.login_button);
loginButton.registerCallback(callbackManager, new FacebookCallback<LoginResult>() {
@Override
public void onSuccess(LoginResult loginResult) {
AccessToken accessToken = loginResult.getAccessToken();
Profile profile = Profile.getCurrentProfile();
info = ("User ID: " +
loginResult.getAccessToken().getUserId() + "\n" + "Auth Token: " + loginResult.getAccessToken().getToken());
}
@Override
public void onCancel() {
info = ("Login attempt canceled.");
}
@Override
public void onError(FacebookException e) {
info = ("Login attempt failed.");
}
});
System.out.println(info);
tracker = new AccessTokenTracker() {
@Override
protected void onCurrentAccessTokenChanged(AccessToken oldAccessToken, AccessToken currentAccessToken) {
}
};
tracker.startTracking();
}
}
此功能來查看登錄
public boolean isLoggedIn() {
AccessToken accessToken = AccessToken.getCurrentAccessToken();
return accessToken != null;
}
這對恢復和Stop方法
@Override
protected void onResume() {
super.onResume();
if (isLoggedIn()){
Intent home = new Intent(this, home.class);
startActivity(home);
}
}
@Override
protected void onStop() {
super.onStop();
tracker.stopTracking();
finish();
}
這是我onActivityResult
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
callbackManager.onActivityResult(requestCode, resultCode, data);
if (resultCode == RESULT_OK) {
Intent home = new Intent(this, home.class);
startActivity(home);
} else {
Toast.makeText(getApplicationContext(), "Unable to login please check your internet connection",Toast.LENGTH_LONG).show();
}
}
我已經做到了這一點,我只是提供這個問題的質詢問題,因此將有助於相互學習更多的東西 –