开发者

images,sdcard,android

I want to write code to display the images only from a particular folder in sdcard. e.g a folder named (/sdcard/folder/). I have the following code, but it displays all the images in the sdcard. What should I add/change in the following code to accompalish my objective.

Should I change the query.If yes how should I change change it.

Please help me. Thanks

`

      String[] img = { MediaStore.Images.Thumbnails._ID };
      imagecursor = managedQuery(MediaStore.Images.Thumbnails.EXTERNAL_CONTENT_URI, img, null,null, MediaStore.Images.Thumbnails.IMAGE_ID + "");
      image_column_index = imagecursor.getColumnIndexOrThrow(MediaStore.Images.Thumbnails._ID);
      count = imagecursor.getCount(); 
      imagegrid = (GridView) findViewById(R.id.sdcard);
      imagegrid.setAdapter(new ImageAdapter(getApplicationContext()));
      imagegrid.setOnItemClickListener(new OnItemClickListener() {
            public void onItemClick(AdapterView parent, View v,int position, long id) {
                  System.gc();
                  String[] proj = { MediaStore.Images.Media.DATA };
                  actualimagecursor = managedQuery(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, proj,null, null, null);
                  actual_image_column_index = actualimagecursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
                  actualimagecursor.moveToPosition(position);
                  String i = actualimagecursor.getString(actual_image_column_index);
                  System.gc();
               开发者_StackOverflow  Intent intent = new Intent(getApplicationContext(), ViewImage.class);
                  intent.putExtra("filename", i);
                  startActivity(intent);
            }
      });
`  


imagecursor = managedQuery(MediaStore.Images.Thumbnails.EXTERNAL_CONTENT_URI, img, null,null, MediaStore.Images.Thumbnails.IMAGE_ID + "");

On above line, you are just passing you Sd card path(MediaStore.Images.Thumbnails.EXTERNAL_CONTENT_URI). I will suggest to create the variable for your path(card/newfolder/) and pass that to managedQuery

Try the answer posted in this question here Using ImageGallery to display images from the SD card?


File folder = new File("/sdcard/images/");
File[] allFiles = folder.list();
//allFiles array contains the files in that folder

Parse the files and get what you want.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜