我仍然希望将文件管理到某些功能,例如放置文件并从DropBox获取文件.现在的问题是当我把一些文件放在DropBox的公用文件夹中,我需要一个URL来分享给应用程序中的联系人.但是在API中,我找不到任何返回要共享的文件的网址的函数(就像在DropBox的Deskotop界面中,用户可以获得一个共享URL来发送给朋友).
有人可以帮我弄清楚如何与应用程序中的联系人共享文件?
解决方法
将不会有更多的公用文件夹,而是可以通过共享链接访问文件.
如果您使用Android DropBox Core Api,那么可以通过以下方式检索共享链接:
// Get the Metadata for a directory Entry dirent = mApi.Metadata(mPath,1000,null,true,null); for (Entry ent : dirent.contents) { String shareAddress = null; if (!ent.isDir) { DropBoxLink shareLink = mApi.share(ent.path); shareAddress = getShareURL(shareLink.url).replaceFirst("https://www","https://dl"); Log.d(TAG,"dropBox share link " + shareAddress); } }
更新:2014/07/20 Dheeraj Bhaskar
与上述功能一起使用以下帮助函数.
由于DropBox开始发送缩短的链接,所以要获得正确的链接有一点问题.
现在,我使用这种方法:
String getShareURL(String strURL) { URLConnection conn = null; String redirectedUrl = null; try { URL inputURL = new URL(strURL); conn = inputURL.openConnection(); conn.connect(); InputStream is = conn.getInputStream(); System.out.println("Redirected URL: " + conn.getURL()); redirectedUrl = conn.getURL().toString(); is.close(); } catch (MalformedURLException e) { Log.d(TAG,"Please input a valid URL"); } catch (IOException ioe) { Log.d(TAG,"Can not connect to the URL"); } return redirectedUrl; }
Note: All of this should be done of course in AsyncTask or Thread. This will produce proper links ready to download
更新2014/07/25:更改收件箱共享网址
关于预期的URL类型的单挑
从DropBox小组:
We wanted to give you a heads up about an upcoming change to the URL
structure of DropBox shared links. While not part of the API,the
change could affect apps that manipulate the URLs returned from the
/shares endpoint or the “preview” link type returned by the Chooser
Drop-in.Links returned will now have a ?dl=0 appended to them.
E.g.,instead of 07001,you’ll receive URLs like this link 07002.