Reputation:
I am using an intent to invoke a file chooser that is external to my app. Some of the file chooser applications return an Uri of scheme "content".
I need to obtain the last modified date of the chosen object. How do I do that when the scheme is "content"? I didn't find an appropriate API.
There is some API that returns a FileDescriptor. But I don't get the last modified date from a FileDescriptor. Any help appreciate.
Best Regards
Upvotes: 3
Views: 2208
Reputation: 4869
In general you can't do what you want - there is no API to get a File for an item described by a "content" URI because a content URI does not have to correspond with a file anyway.
In practice it is possible to get a File path for some content URIs:
as you describe, sometimes you can get lucky, and manipulate the content uri by changing the content scheme to a file scheme
If the content URI came from the Media store, then you can do a query to get the file path
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); }
There are a whole host of other questions asking pretty much the same thing that provide further ideas (or slightly different working of the same ideas)
Upvotes: 3