根據DropBox對此處所述的更改:https://www.dropbox.com/help/16/en 將不再有公共文件夾,而是可以通過共享鏈接訪問文件。
如果你使用Android的DropBox核心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);
}
}
UPDATE:由Dheeraj巴斯卡爾 使用下面的輔助函數非常久遠上述功能2014年7月20日。 因爲DropBox開始發送縮短的鏈接,所以得到正確的鏈接會有點問題。 現在,我正在使用這種方法:
我們只需加載URL,按照重定向並獲取新的URL。
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;
}
注:所有這一切都應該在的AsyncTask或線程來完成課程。這將產生準備下載正確的鏈接
更新2014/07/25:變化的dropbox共享URL,
的那種URL的擡頭期待
從Dropbox的團隊:
我們想給你一個關於即將到來的修改Dropbox共享鏈接的URL 結構的提示。雖然不是API的一部分,但 更改可能會影響操縱從 /shares端點返回的URL或由Chooser 插入返回的「預覽」鏈接類型的應用程序。
返回的鏈接現在會附加一個?dl = 0。
例如,而不是 https://www.dropbox.com/s/99eqbiuiepa8y7n/Fluffbeast.docx,您會收到 網址 這樣的鏈接 https://www.dropbox.com/s/99eqbiuiepa8y7n/Fluffbeast.docx?dl=0。
我發現了一些文檔:https://www.dropbox.com/developers/docs 你是指別的東西嗎? – KPthunder 2011-04-23 17:16:08
@KPthunder ..謝謝你的回覆...我已經看到這個文檔已經沒有方法提及共享那是我的問題。 謝謝 – 2011-04-27 09:05:21