gpt4 book ai didi

android - 是否有 ContentResolver 来获取文件而不是 FileDescriptor?

转载 作者:太空狗 更新时间:2023-10-29 13:25:08 27 4
gpt4 key购买 nike

我正在使用 Intent 调用我的应用程序外部的文件选择器。一些文件选择器应用程序返回方案“内容”的 Uri。

我需要获取所选对象的最后修改日期。当方案是“内容”时我该怎么做?我没有找到合适的 API。

有一些 API 返回一个 FileDescriptor。但我没有从 FileDescriptor 获得最后修改日期。任何帮助表示赞赏。

最好的问候

最佳答案

一般来说,您无法为所欲为 - 没有 API 可以为“内容”URI 描述的项目获取文件,因为内容 URI 不必与文件相对应。

在实践中,可以获取某些内容 URI 的文件路径:

  • 正如您所描述的,有时您会很幸运,并通过将内容方案更改为文件方案来操纵内容 uri

  • 如果内容 URI 来自媒体存储,那么您可以查询以获取文件路径

    public static String getPathnameFromMediaUri(Activity activity, Uri contentUri)    {        String[] projection = { MediaStore.Images.Media.DATA };        Cursor cursor = activity.managedQuery(contentUri, projection, null, null, null);        int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);        cursor.moveToFirst();        return cursor.getString(column_index);    }

还有一大堆其他问题问的几乎相同的事情提供了进一步的想法(或相同想法的略有不同的工作方式)

关于android - 是否有 ContentResolver 来获取文件而不是 FileDescriptor?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22272418/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com