【问题标题】:Get file name of download file using download manager in android在android中使用下载管理器获取下载文件的文件名
【发布时间】:2017-03-23 09:39:14
【问题描述】:

据我们所知,DownloadManager.COLUMN_LOCAL_FILENAMEdeprecated 形式 api 级别 24,并且要获取从下载管理器下载的文件的文件名,谷歌正在使用 ContentResolver.openFileDescriptor() 访问文件名

谁能建议我如何使用ContentResolver.openFileDescriptor()访问文件名

【问题讨论】:

    标签: android android-download-manager


    【解决方案1】:

    您无法通过openFileDescriptor() 访问文件名。由于您是请求下载的人,因此您已经知道文件名是什么。

    【讨论】:

    • 感谢您的回答,那么 ContentResolver.openFileDescriptor() 的用途是什么?
    • @user2534612:获取下载的内容。老实说,我不知道为什么建议这样做,因为您已经可以访问文件所在的位置(否则,AFAIK,您将无法将下载请求排入队列)。
    【解决方案2】:

    我没有使用 ContentResolver.openFileDescriptor()。

    要检索下载文件的旧绝对路径:

    String absolutePath =  Uri.parse(cursor.getString(cursor.getColumnIndex(DownloadManager.COLUMN_LOCAL_URI))).getPath();
    

    当然还有:

    File file = new File(absolutePath);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-01-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-08-27
      • 2018-06-10
      相关资源
      最近更新 更多