3
我正在使用列出所有圖像的代碼,並且我試圖弄清楚如何僅從特定文件夾獲取圖像,而不是所有圖像。下面是我使用的代碼:Android從SD卡獲取圖像
ArrayList<Bitmap> images = new ArrayList<Bitmap>();
String[] projection = {MediaStore.Images.Thumbnails.DATA};
Uri uri = Uri.parse("content://media/external/images/media");
cursor = managedQuery(uri, projection, null, null, null);
//cursor = managedQuery(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, projection, null, null, null);
Log.i("MediaStore.Images.Media.EXTERNAL_CONTENT_URI", "MediaStore.Images.Media.EXTERNAL_CONTENT_URI: " + MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
if(cursor.getCount()==0){
Log.i("No Cards","No Cards");
cursor.close();
} else if(cursor.getCount()>0){
for(cursor.moveToFirst(); cursor.moveToNext(); cursor.isAfterLast()){
int columnIndex = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
String imagePath = cursor.getString(columnIndex);
Log.i("imagePath", "imagePath: " + imagePath);
Bitmap b = BitmapFactory.decodeFile("/Stampii" + imagePath, null);
images.add(b);
}
}
,我想要做的事情是從imagePath: /mnt/sdcard/Stampii/MediaCategory-251.jpg
Stampii文件夾獲取的圖像,但我不知道如何進入正確的道路到該文件夾。我已經嘗試過:
Uri uri = Uri.parse("content://media/external/images/media/mnt/sdcard/Stampii");
任何解決方案?