0

在我的项目中,我想添加很多新图像并删除其他图像,并且我想在活动的 res 文件夹中获取所有可绘制对象的列表。我怎样才能得到它?或者我应该使用assets 文件夹并从那里获取图像列表?

4

2 回答 2

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

于 2013-07-12T17:34:44.773 回答
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();
}
}

希望这可以帮助!!!!!!!!

于 2013-07-12T17:39:17.493 回答