android dropbox切换账户,android - 在Android应用程序中集成Dropbox,但没有登录弹出窗口 - 堆栈内存溢出...

在onCreate()中写

AppKeyPair pair = new AppKeyPair(ACCESS_KEY, ACCESS_SECRET);

session = new AndroidAuthSession(pair, AccessType.APP_FOLDER);

dropbox = new DropboxAPI(session);

SharedPreferences prefs = getSharedPreferences(DROPBOX_NAME, 0);

String key = prefs.getString(ACCESS_KEY, null);

String secret = prefs.getString(ACCESS_SECRET, null);

if (key != null && secret != null) {

Log.d("key secret", key + " " + secret);

AccessTokenPair token = new AccessTokenPair(key, secret);

dropbox.getSession().setAccessTokenPair(token);

}

if (key == null && secret == null)

dropbox.getSession().startAuthentication(DropboxActivity.this);

并在onResume()中写

if (dropbox.getSession().isLinked()) {

try {

loggedIn(true);

doAction();

} catch (IllegalStateException e) {

Toast.makeText(this, "Error during Dropbox authentication",

Toast.LENGTH_SHORT).show();

}

} else if (dropbox.getSession().authenticationSuccessful()) {

try {

session.finishAuthentication();

TokenPair tokens = session.getAccessTokenPair();

SharedPreferences prefs = getSharedPreferences(DROPBOX_NAME, 0);

Editor editor = prefs.edit();

editor.putString(ACCESS_KEY, tokens.key);

editor.putString(ACCESS_SECRET, tokens.secret);

editor.commit();

loggedIn(true);

doAction();

} catch (IllegalStateException e) {

Toast.makeText(this, "Error during Dropbox authentication",

Toast.LENGTH_SHORT).show();

}

}

它对我来说很好

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值