I am trying to implement on click media(Video/Images) function in my chat app when user click on any media it opens new fragment with app folder of images or video like whatsapp and telegram.
I implemented code which open app folder for images and shows all images. Here i need to show all images like i am doing but show first image which user clicked on. for this i have image full name like this /storage/emulated/0/xmpp/Media/xmpp Images/xmpp IMG_1582477568462.jpg .
For video i am also using same code but i am getting 0 result from cursor. I don't know what what's wrong with my code
private ArrayList<String> getFolderItems(String folderName, String fileName, int type){
String[] colums = null ;
String orderBy = null;
String columsName = null;
Uri uri = null;
String selection = null;
String[] selectionArgs = null;
String folder = /storage/emulated/0/xmpp/Media/xmpp Images+folderName;
Log.d(TAG, "getFolderItems: "+folderName+" "+fileName+" "+type);
Log.d(TAG, "getFolderItems: Destination Folder == "+folder);
// 0 for images 1 for video
if (type == 0){
Log.d(TAG,"Type == 0");
colums = new String[]{MediaStore.Images.Media.DATA, MediaStore.Images.Media._ID};
orderBy = MediaStore.Images.Media.DATE_ADDED + " DESC";
uri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
columsName = MediaStore.Images.Media.DATA;
selection = MediaStore.Images.Media.DATA + " like ? ";
selectionArgs = new String[]{"%" + folder + "%"};
}else {
Log.d(TAG,"Type == 1");
colums = new String[]{MediaStore.Video.Media.DATA, MediaStore.Video.Media._ID};
orderBy = MediaStore.Video.Media.DATE_ADDED + " DESC";
uri = MediaStore.Video.Media.EXTERNAL_CONTENT_URI;
columsName = MediaStore.Video.Media.DATA;
selection = MediaStore.Video.Media.DATA + " like ? ";
selectionArgs = new String[]{"%" + folder + "%"};
}
Cursor cursor = MyApplication.getmContext().getContentResolver().query(
uri,
colums,
selection,
selectionArgs,
orderBy);
int count = cursor.getCount();
if (galleryItems == null){
galleryItems = new ArrayList<>();
}
for (int i = 0; i <count ; i++) {
cursor.moveToPosition(i);
int index = cursor.getColumnIndex(columsName);
Log.d(TAG, "getFolderItems: "+cursor.getString(index));
galleryItems.add(cursor.getString(index));
}
cursor.close();
Log.d(TAG, "getFolderItems: Gallery Item Size == "+galleryItems.size());
return galleryItems;
}
for showing images/video i am using RecyclerView
and i am also cross checked if video exist in folder with correct name
Video_1583239285257.mp4
So above code has 2 issue which i need to resolve. Please help me in this.
1: Not getting any result for video cursor
2: Unable to move to particular image user click when showing to user