How to get photos from getExternalFilesDir

71 Views Asked by At

I am implementing a gallery app where i want to use photpos stored in getExternalFilesDir(Environment.DIRECTORY_PICTURES) directory .. Here is the code but what i get is all the gallery photo pictures , how can i figure this out :

    public class GalleryPhotoActivity extends AppCompatActivity {
ActivityGalleryPhotoBinding binding;
ArrayList<Uri> imageuris= new ArrayList<>();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        binding= ActivityGalleryPhotoBinding.inflate(getLayoutInflater());
        setContentView(binding.getRoot());

        String [] projection=new String[]{
            MediaStore.Images.Media._ID,
                MediaStore.Images.Media.SIZE,
                MediaStore.Images.Media.DATE_MODIFIED
        };
        String selection=null;
        String[] selectionArgs =null;
        String orderby=null;
        Uri content_uri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
        Cursor cursor=getContentResolver().query(content_uri,projection,selection,selectionArgs,orderby);
        if(cursor!=null){
            cursor.moveToPosition(0);
            while(true){
                long id= cursor.getLong(cursor.getColumnIndexOrThrow(MediaStore.Images.Media._ID));
                Uri image_uri= ContentUris.withAppendedId(MediaStore.Images.Media.EXTERNAL_CONTENT_URI,id);

                imageuris.add(image_uri);
                if(!cursor.isLast())
                cursor.moveToNext();
                else
                    break;
            }
            binding.rv.setLayoutManager(new GridLayoutManager(this,3));
            RvAdapter adapter = new RvAdapter(imageuris);
            binding.rv.setAdapter(adapter);
        }



    }
}
0

There are 0 best solutions below