问题
I am trying to get all video available in gallery with below code,
String[] proj = { MediaStore.Video.Media._ID,MediaStore.Video.Media.DATA,MediaStore.Video.Media.DISPLAY_NAME,MediaStore.Video.Media.SIZE };
videocursor = managedQuery(MediaStore.Video.Media.EXTERNAL_CONTENT_URI,proj, null,null, null);
int count = videocursor.getCount();
But I always get count = 0
, where was I made mistake ?
I also tried
Cursor videocursor = managedQuery(MediaStore.Video.Media.INTERNAL_CONTENT_URI, proj, null, null, null);
回答1:
Do like this -
String[] proj = { MediaStore.Video.Media.DATA,
MediaStore.Video.Media._ID, MediaStore.Video.Media.TITLE,
MediaStore.Video.Media.DISPLAY_NAME,
MediaStore.Video.Media.MIME_TYPE,
MediaStore.Video.Media.DURATION,
MediaStore.Video.Media.SIZE,};
String orderBy = android.provider.MediaStore.Video.Media.TITLE;
Cursor videocursor = managedQuery(MediaStore.Video.Media.EXTERNAL_CONTENT_URI,
proj, null, null, orderBy);
To get the size, you can use
int count = videocursor.getCount();
EDIT managedQuery() is deprecated
来源:https://stackoverflow.com/questions/24547130/get-all-captured-videos-in-android-as-a-list