display videos from specific folder from sd card i

2019-08-02 09:41发布

问题:

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?

回答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");


回答2:

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);


回答3:

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..........