使用ContentResolver查询媒体库并获取最新的URI。
示例代码:
ContentResolver resolver = getContentResolver();
Uri uri = MediaStore.Video.Media.EXTERNAL_CONTENT_URI;
String[] projection = new String[]{MediaStore.Video.Media._ID};
String sortOrder = MediaStore.Video.Media.DATE_MODIFIED + " DESC LIMIT 1";
Cursor cursor = resolver.query(uri, projection, null, null, sortOrder);
if (cursor.moveToFirst()) {
long id = cursor.getLong(cursor.getColumnIndex(MediaStore.Video.Media._ID));
Uri videoUri = ContentUris.withAppendedId(uri, id);
// 使用videoUri进行操作
}
cursor.close();