![](/img/trans.png)
[英]Upload files using retrofit 2 without the file instance (filedescriptor or inputstream), or obtain the file instance from the content uri
[英]Is there a ContentResolver to obtain a File instead of a FileDescriptor?
我正在使用一個意圖來調用我的應用程序外部的文件選擇器。 一些文件選擇器應用程序返回一個方案“內容”的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); }
還有許多其他問題提出了幾乎相同的東西,提供了進一步的想法(或相同的想法略有不同的工作)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.