如何从android中的res文件夹获取图像列表

时间:2013-07-12 17:30:23

标签: android

在我的项目中,我想添加大量新图像并删除其他图像,我想获取活动中res文件夹中所有drawables的列表。我怎么能得到它?或者我应该使用assests文件夹并从那里获取图像列表?

2 个答案:

答案 0 :(得分:0)

public void searchSDCardForImage() {

        String path = null;

        String uri = MediaStore.Images.Media.DATA;
        String condition = uri + " like '%/GetImageFromThisDirectory/%'";
        String[] projection = { uri, MediaStore.Images.Media.DATE_ADDED,
                MediaStore.Images.Media.SIZE };
        Vector additionalFiles = null;
        try {
            if (additionalFiles == null) {
                additionalFiles = new Vector<String>();
            }



            Cursor cursor = managedQuery(
                    MediaStore.Images.Media.EXTERNAL_CONTENT_URI, projection,
                    condition, null, null);
            if (cursor != null) {

                boolean isDataPresent = cursor.moveToFirst();

                if (isDataPresent) {

                    do {

                        path = cursor.getString(cursor.getColumnIndex(uri));
System.out.println("...path..."+path);
additionalFiles.add(path);
            }while(cursor.moveToNext());
                }
            if (cursor != null) {
                cursor.close();
            }
            }

        } catch (Exception e) {
            e.printStackTrace();
        }
    }

还有:http://developer.android.com/guide/topics/resources/accessing-resources.html

答案 1 :(得分:0)

使用此,

Field[] list = R.drawable.class.getFields();
BitmapDrawable[] drawables=new BitmapDrawable[list.length];
for (int i=0;i<list.length;i++){
int id=list[i].getInt(null);
try{
drawables[i]=(BitmapDrawable)getResources().getDrawable(id);
} catch (NotFoundException e) {
// TODO Auto-generated catch block
    e.printStackTrace();
} catch (IllegalArgumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalAccessException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}

希望这有助于!!!!!!!!