So, I have googled this, but all I get is how to generate never expiring facebook page token.
Scenario is this: I want to log in user from my android application. Then, when he receieves token, that token will go to server. Now, what I want to do is this: I want to make that token a never expired one, so I don't need to ask user to log in again from the application. Is this possible?
答案 0 :(得分:0)
Globals.java
import android.app.Application;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
/**
* Created by Furkan on 28.10.2016.
*/
public class Globals extends Application{
@Override
public void onCreate() {
super.onCreate();
}
private String token;
public void setConfig(String key, String value) {
try {
SharedPreferences spref = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
SharedPreferences.Editor spref_edit = spref.edit();
spref_edit.putString(key, value);
spref_edit.commit();
} catch (Exception e) {
Log.i("FD", e.getMessage());
}
}
public String getConfig(String key) {
SharedPreferences spref = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
return spref.getString(key, "");
}
public void delConfig(String key) {
SharedPreferences spref = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
SharedPreferences.Editor spref_edit = spref.edit();
spref_edit.remove(key);
spref_edit.commit();
}
public void clearConfig() {
SharedPreferences spref = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
SharedPreferences.Editor spref_edit = spref.edit();
spref_edit.clear();
spref_edit.commit();
}
public void setToken(String token) {
this.token = token;
setConfig("token", token);
}
}
此课程将帮助您保存令牌。
你应该在主课堂上;
Globals g;
到达令牌后,您应该保存它;
g.setToken(token);
如果您想跳过登录屏幕,如果有保存的令牌,您应该执行类似的操作;
if(!g.getConfig("token").isEmpty()){
Intent intent = new Intent(Main.this, BlaBlaBla.class);
startActivity(intent);
祝你好运!