我想检测每个Android设备上的相机文件夹.从我读过这个文件夹从制造商到另一个不同,也不能保证会有设备上甚至DCIM文件夹.
这是我现在用来获取文件的方法:
private static final SetFILTER_FOLDERS = new HashSet ( Arrays.asList(new String[] { "camera", "100andro", "100media" })); private Set getCameraPictures() { final String[] columns = new String[] { MediaStore.Images.ImageColumns._ID, MediaStore.Images.ImageColumns.DATA, MediaStore.Images.ImageColumns.BUCKET_DISPLAY_NAME, MediaStore.Images.ImageColumns.DISPLAY_NAME, MediaStore.Images.ImageColumns.DATE_TAKEN, MediaStore.Images.ImageColumns.MIME_TYPE }; // Order by options - by date & descending final String orderBy = MediaStore.Images.ImageColumns.DATE_TAKEN + " DESC"; // Stores all the images from the gallery in Cursor final Cursor cursor = getContentResolver().query( MediaStore.Images.Media.EXTERNAL_CONTENT_URI, // base URI for // the Images columns, // Which columns to return null, // Which rows to return (all rows) null, // Selection arguments (none) orderBy); // Ordering // Total number of images int count = cursor.getCount(); // Create an array to store path to all the images String[] picturesPath = new String[count]; if (cursor.moveToFirst()) { int dataColumn = cursor .getColumnIndex(MediaStore.Images.Media.DATA); int bucketColumn = cursor .getColumnIndex(MediaStore.Images.Media.BUCKET_DISPLAY_NAME); do { if (FILTER_FOLDERS.contains(cursor.getString(bucketColumn) .toLowerCase(Locale.getDefault()))) { // Store the path of the image picturesPath[cursor.getPosition()] = cursor .getString(dataColumn); } } while (cursor.moveToNext()); } // Close the cursor if (null != cursor) { cursor.close(); } return new HashSet (Arrays.asList(picturesPath)); }
但这也是从其他地方返回的图像......我怎样才能只检索用相机拍摄的图像?如果没有本地方法可以执行此操作,我在哪里可以找到每个制造商使用的文件夹的名称(尽可能多),以便我可以通过BUCKET_DISPLAY_NAME过滤它?
谢谢
LE:
我已更新方法以获取设备上的图像并过滤文件夹.