Reputation: 477
In my application, i use dropbox api to keep some files, it's ok. After authentication i close the app and re-launch app. It needs re-authentication each time i opened the application.I want the application to remember my session.
Upvotes: 2
Views: 642
Reputation: 2067
Dropbox tutorial suggest storing the authentication token as SharedPreferences, so you could restore it later.
You can see an example application in dropbox SDK located in \dropbox-android-sdk-1.6\examples\DBRoulette
.
In the activity's onCreate()
method check if preference is stored and if it is then instean of calling authentication window use session.setOAuth2AccessToken(RESTORED_TOKEN);
Sample code to do this:
public void onCreate() {
AppKeyPair appKeys = new AppKeyPair(APP_KEY, APP_SECRET);
AndroidAuthSession session = new AndroidAuthSession(appKeys, ACCESS_TYPE);
mDBApi = new DropboxAPI<AndroidAuthSession>(session);
String token = getTokenFromPreferences();
if (token != null) {
session.setOAuth2AccessToken(token);
} else {
mDBApi.getSession().startOAuth2Authentication(MyActivity.this);
}
}
Upvotes: 1