Android Dropbox Core API实施

时间:2015-03-01 12:21:05

标签: android dropbox

我正在尝试在我的Android应用程序中实现CORE API。

我正在关注Dropbox教程。

https://www.dropbox.com/developers/core/start/android

final static private String APP_KEY = "INSERT_APP_KEY";
final static private String APP_SECRET = "INSERT_APP_SECRET";

// In the class declaration section:
private DropboxAPI<AndroidAuthSession> mDBApi;

// And later in some initialization function:
AppKeyPair appKeys = new AppKeyPair(APP_KEY, APP_SECRET);
AndroidAuthSession session = new AndroidAuthSession(appKeys);
mDBApi = new DropboxAPI<AndroidAuthSession>(session);

但是,我不知道在哪里放这行代码?

mDBApi.getSession().startOAuth2Authentication(MyActivity.this);

当我把它放在Oncreate()函数中时,我得到了一个无限循环的Dropbox App验证帐户。

有人可以向我展示一个功能强大的代码示例吗?

我也想知道如何通过Dropbox CORE API从Dropbox读取文件?

我应该首先下载文件,将其保存到移动内存中,然后像本地文件一样访问它吗?

提前致谢。

1 个答案:

答案 0 :(得分:0)

来自官方documentation

  

我们首先调用startOAuth2Authentication()方法   会要求用户授权您的应用。如果是Dropbox应用程序   安装后,SDK将切换到它,因此用户不必签名   in,如果没有,它将回退到浏览器。

这意味着当您准备好与Dropbox服务器启动事务时,必须调用此方法。看起来这种方法首先检查Dropbox在手机上是否存在并对用户进行身份验证,如果没有找到则将他发送到网页登录。所以听起来这种方法会激活Dropbox的特殊意图应用或设备的浏览器要处理,从而使不适合将其置于onCreate()方法中。应该在启动与服务器的事务之前放置此方法。 (例如,一个readFile()方法,只需按一下按钮就可以调用一次。

从扫描官方文档看来,为了读取文件,您必须首先下载该文件,将其另存为缓存(临时)文件,阅读它,当你完成删除它。