【问题标题】:Intent.ACTION_VIEW returning wrong file pathIntent.ACTION_VIEW 返回错误的文件路径
【发布时间】:2014-02-07 18:56:32
【问题描述】:

我的应用打算使用 ACTION_VIEW 启动文件。 以下代码返回所选文件的文件路径

 if(Intent.ACTION_VIEW.equals(action)){
String Path = intent.getDataString();
    //file processing code
    }

当所选文件中没有空格时,它可以正常工作。例如路径变为“/mnt/sdcard/sample.pdf”,但是当我选择一个名称中带有空格的文件时,例如“/mnt/sdcard/4C 1099 + 2 WOOO6.pdf”路径变为“/mnt/sdcard/4C %20%20%201099%20%20%20%2B%20%202%20W0006.pdf"

有什么帮助吗?

【问题讨论】:

    标签: android android-intent actionview


    【解决方案1】:
     if(Intent.ACTION_VIEW.equals(action)){
     Uri uri = intent.getData();
     path = uri.getPath();
         path = path.replace("%20", " ");
     }
    

    【讨论】:

    • 哇它好用,我一直在使用 intent.getEncodedPath 而不是 intent.getPath。
    • 如果您真的认为答案是 ri8,请在 ri8 上播放 tik
    猜你喜欢
    • 2013-07-02
    • 1970-01-01
    • 2020-01-28
    • 2019-03-19
    • 1970-01-01
    • 2020-03-24
    • 1970-01-01
    • 2021-12-20
    • 1970-01-01
    相关资源
    最近更新 更多