【问题标题】:pass location of a file in FTP through intent通过意图在 FTP 中传递文件的位置
【发布时间】:2018-02-01 11:40:31
【问题描述】:

我想使用我的 android 应用程序中的意图传递位于 FTP 中的文件的 URL,以便在 google chrome 中打开它。我正在尝试将它传递给 google chrome 应用程序浏览器,但它在关键字 ftp 之后不包含冒号。 我路过

http://ftp://demo.wftpserver.com/download/manual_en.pdf/

它会在 URL 框中显示以下链接

http://ftp//demo.wftpserver.com/download/manual_en.pdf/

它在 ftp 之后缺少一个冒号,我想在 URL 中也传递那个冒号。

我使用的代码是

    String url = "http://ftp://demo.ftpserver.com/download/manual_en.pdf";
    String uri = "googlechrome://navigate?url=" + url;
    Intent i = new Intent(Intent.ACTION_VIEW);
    i.setData(Uri.parse(uri));

    i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    i.setPackage("com.android.chrome");

任何帮助将不胜感激。

【问题讨论】:

    标签: android ftp


    【解决方案1】:

    只需使用正确的链接:

    String url = "ftp://demo.ftpserver.com/download/manual_en.pdf";
    

    我会这样做:

    Intent i = new Intent(Intent.ACTION_VIEW);
    i.setData(Uri.parse("ftp://ftp.hosteurope.de/"));
    i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    i.setPackage("com.android.chrome");
    

    【讨论】:

    • Puh 我真的花了 7 分钟才找到一个开放的 ftp 服务器来验证我的答案。只需使用“我的”网址作为 uri,它应该可以工作
    • 我对 Kotlin 不熟悉,能否提供 Java 代码
    • 我将代码转换回 Java。顺便说一句,你应该试一试。
    • 这不会打开给定的 URL。它会打开一个空白选项卡。添加 http:// 后,它会打开问题中显示的 URL。您能否提供一个解决方案,让我在 http:// 之后传递一个额外的冒号?
    猜你喜欢
    • 2012-07-29
    • 2012-04-26
    • 2013-03-24
    • 1970-01-01
    • 2017-11-06
    • 1970-01-01
    • 1970-01-01
    • 2014-06-27
    相关资源
    最近更新 更多