我无法清除Facebook的领域。我展示了图像,名称,性别。当我点击Facebooklogout按钮时,我想清除这三个字段。谁能帮帮我呢?
公共类MainActivity扩展了AppCompatActivity {
private LoginButton loginButton;
private CallbackManager callbackManager;
private ProfilePictureView profilePictureView;
private LinearLayout infoLayout;
private TextView email;
private TextView gender;
private TextView username;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
/*We have to initialize before using any methods with sdkIntialise()*/
FacebookSdk.sdkInitialize(MainActivity.this);
loginButton = (LoginButton) findViewById(R.id.login_button);
email = (TextView) findViewById(R.id.email);
gender = (TextView) findViewById(R.id.gender);
username = (TextView) findViewById(R.id.vname);
infoLayout = (LinearLayout) findViewById(R.id.layout_info);
infoLayout.setVisibility(View.GONE);
profilePictureView = (ProfilePictureView) findViewById(R.id.vimage);
loginButton.setReadPermissions(Arrays.asList("public_profile, email, user_birthday"));
/*initialize an instance of CallbackManager*/
callbackManager = CallbackManager.Factory.create();
loginButton.registerCallback(callbackManager, new FacebookCallback<LoginResult>() {
@Override
public void onSuccess(LoginResult loginResult) {
GraphRequest graphRequest = GraphRequest.newMeRequest(loginResult.getAccessToken(), new GraphRequest.GraphJSONObjectCallback() {
@Override
public void onCompleted(JSONObject object, GraphResponse response) {
setProfileView(object);
}
});
Bundle parameters = new Bundle();
parameters.putString("fields", "id,name,email,gender,birthday");
graphRequest.setParameters(parameters);
graphRequest.executeAsync();
}
@Override
public void onCancel() {
}
@Override
public void onError(FacebookException error) {
Toast.makeText(MainActivity.this, "Error to Login Facebook", Toast.LENGTH_SHORT).show();
}
});
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
callbackManager.onActivityResult(requestCode, resultCode, data);
}
private void setProfileView(JSONObject object) {
try {
email.setText(object.getString("email"));
gender.setText(object.getString("gender"));
username.setText(object.getString("name"));
profilePictureView.setPresetSize(ProfilePictureView.NORMAL);
profilePictureView.setProfileId(object.getString("id"));
infoLayout.setVisibility(View.VISIBLE);
} catch (JSONException e) {
e.printStackTrace();
}
}
}
答案 0 :(得分:1)
您好注销,您可以使用以下代码: 获取当前访问令牌,然后调用fb logout函数。
> if (AccessToken.getCurrentAccessToken() != null) {
> LoginManager.getInstance().logOut();
> }
注销后,您必须刷新布局或在代码后启动您需要的相同活动:
Intent openMainActivity = new Intent(MainActivity.this, MainActivity.class);openMainActivity.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK|Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(openMainActivity);
希望有所帮助