是否有方法检查用户点击退出按钮的时间,我有这个登录我的Android应用程序:
FacebookSdk.sdkInitialize(this.getApplicationContext());
callbackManager = CallbackManager.Factory.create();
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
final SharedPreferences.Editor editor = sharedPreferences.edit();
LoginManager.getInstance().registerCallback(callbackManager,
new FacebookCallback<LoginResult>() {
@Override public void onSuccess(LoginResult loginResult) {
// App code
Toast.makeText(getApplicationContext(), "Login successful" + loginResult.getAccessToken().toString(), Toast.LENGTH_LONG).show();
GraphRequest request = GraphRequest.newMeRequest(
loginResult.getAccessToken(),
new GraphRequest.GraphJSONObjectCallback() {
@Override
public void onCompleted(
JSONObject object,
GraphResponse response) {
// Application code
//textView.setText(response.toString());
JSONObject j_user = response.getJSONObject();
try {
KEY_ID = object.getString("id");
KEY_EMAIL = object.getString("email");
KEY_NAME = object.getString("name");
} catch (JSONException e) {
e.printStackTrace();
}
Log.i("stringazzo", response.toString());
Log.i("STRING", object.toString());
// Log.i("string", KEY_EMAIL);
// Log.i("string", KEY_ID);
// Log.i("string", KEY_NAME);
// Log.i("SHAREDPREFS",KEY_NAME);
// Log.i("SHAREDPREFS",KEY_EMAIL);
editor.putString("name", KEY_NAME);
editor.putString("email", KEY_EMAIL);
editor.putString("id", KEY_ID);
editor.commit();
System.out.println(editor.commit());
}
});
Bundle parameters = new Bundle();
parameters.putString("fields", "id,name,email");
request.setParameters(parameters);
request.executeAsync();
}
@Override
public void onCancel() {
Toast.makeText(getApplicationContext(), "Login canceled", Toast.LENGTH_SHORT).show();
}
@Override
public void onError(FacebookException exception) {
Toast.makeText(getApplicationContext(), "Login error"+exception.getMessage().toString(), Toast.LENGTH_SHORT).show();
}
});
当用户登录我的应用程序时,我从Facebook获取一些数据并将其保存在SharedPreferences中,当用户登录时,登录按钮变为注销,我希望当用户点击注销按钮时,我的所有SharedPreferences都将设置为“0 “价值观。
也在我的iphone应用程序中
我该怎么做?
答案 0 :(得分:0)
facebook登录和注销按钮是相同的,并在点击时触发相同的事件。因此,您需要做的是,验证用户是否已登录。
像这样:
Profile.fetchProfileForCurrentAccessToken(); //manually force profile fetching from current token
if(Profile.getCurrentProfile() != null) { //if it available
Log.d("TAG", "LOGGED ");
} else {
Log.d("TAG", "Profile is null UNLOGGED");
}
我希望它有所帮助。 ;)