1

i am trying to populate listview with video files from a folder created on sd card. I am using

managedQuery(MediaStore.Video.Media.EXTERNAL_CONTENT_URI,mystring, null, null, null);

But it populates all videos saved in sdcard, but i want only those videos which are saved in specific folder. I have also used

Uri uri = Uri.fromFile(filepath);
cursor = managedQuery(uri, mystring , null , null , null); 

and

Uri uri = Uri.parse(filepath);
cursor = managedQuery(uri, mystring , null , null , null);

But it doesn't work. I have tried lot and got help from google still not succeded. Is there any way to give path of that folder? or any other way?

Larik
  • 99
  • 3
  • 10

3 Answers3

1

you can use this code for get videos from specific folder as:

String selection=MediaStore.Video.Media.DATA +" like?";
        String[] selectionArgs=new String[]{"%FolderName%"};
        videocursor = managedQuery(MediaStore.Video.Media.EXTERNAL_CONTENT_URI,
                parameters, selection, selectionArgs, MediaStore.Video.Media.DATE_TAKEN + " DESC");
Deepak Jangir
  • 580
  • 5
  • 13
0

You can get a files form a specific location like this

item = new ArrayList<String>();
 path = new ArrayList<String>();

 File f = new File("/sdcard/");

 // or you can use File f=new File(Environment.getExternalStorageDirectory().getPAth());
 File[] files = f.listFiles();


 for(int i=0; i < files.length; i++)
 {
   File file = files[i];
   path.add(file.getPath());
   if(file.isDirectory())
    item.add(file.getName() + "/");
   else
    item.add(file.getName());
 }

 ArrayAdapter<String> fileList =
  new ArrayAdapter<String>(this, R.layout.row, item);
 setListAdapter(fileList);
Andrei
  • 2,607
  • 1
  • 23
  • 26
  • Thanks Andrei. I have tried your code it gives some errors such as setListAdapter is undefined for the type activity. And i click any row for that should i write private OnItemClickListener videogridlistener = new OnItemClickListener() method? – Larik Oct 16 '11 at 20:17
  • Actually i am using cursor here. How can i use cursor with that? – Larik Oct 16 '11 at 20:18
  • Hi, there is an example [here](http://stackoverflow.com/questions/5039779/displaying-images-from-a-specific-folder-on-the-sdcard-using-a-gridview) on displaying images using a cursor. You might be able to adapt it to your needs. – Andrei Oct 16 '11 at 20:43
  • Also, there is another post [here](http://stackoverflow.com/questions/4633260/read-data-from-sdcard-in-android) which shows how you could adapt the code that I posted above with a `onListItemClick()`. – Andrei Oct 16 '11 at 20:45
0

hey managedquery search the whole sdcard not the specific folder . the above method is true of display the name of file but if you to display thumbnail create thumbmail and store in in Hashmap and populate it to the list of gallery adapter..........

Vipin Sahu
  • 1,441
  • 1
  • 18
  • 29