Android   发布时间:2022-04-28  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了android – Dropbox共享文件URL大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在开发一个 Android应用程序,并使用DropBox来组织文件.我正在探索DropBox API,但其描述和帮助是有限的,因为没有DropBox API的文档.

我仍然希望将文件管理到某些功能,例如放置文件并从DropBox获取文件.现在的问题是当我把一些文件放在DropBox的公用文件夹中,我需要一个URL来分享给应用程序中的联系人.但是在API中,我找不到任何返回要共享的文件的网址的函数(就像在DropBox的Deskotop界面中,用户可以获一个共享URL来发送给朋友).

有人可以帮我弄清楚如何与应用程序中的联系人共享文件

还是使用DropBox Android API分享文件的其他方法

解决方法

根据DropBox的改变,这里有: https://www.dropbox.com/help/16/en
将不会有更多的公用文件夹,而是可以通过共享链接访问文件.

如果您使用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开始发送缩短的链接,所以要获得正确的链接有一点问题.
现在,我使用这种方法

我们只需加载网址,按照重定向获取新的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;
}

更新2014/07/25:更改收件箱共享网址
关于预期的URL类型的单挑
从DropBox小组:

大佬总结

以上是大佬教程为你收集整理的android – Dropbox共享文件URL全部内容,希望文章能够帮你解决android – Dropbox共享文件URL所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。