how to open only image from file manager folders in android activity programmatically

2k Views Asked by At

i'm developing an android gallery application,so i want to open only image/photo folder from when i click the file chooser button,

i'm trying to open it but all unnecessary folders are showing the open activity (music/video/contact/.etc).i want to open only the that image and file folders.

this is my file chooser code. i'm using ACTION_PICK for the open activity

 public void showFileChooser(View v) {

            Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
            intent.setType("/*");

            if(Build.VERSION.SDK_INT >= 15 && Build.VERSION.SDK_INT <= 18){
                intent.putExtra(Intent.EXTRA_LOCAL_ONLY,true);
                intent.setAction(Intent.ACTION_GET_CONTENT);

                try {
                    startActivityForResult(
                            Intent.createChooser(intent, "Select Picture"),FILE_SELECT_CODE);
                } catch (ActivityNotFoundException ex) {
                    // Potentially direct the user to the Market with a Dialog
                    Toast.makeText(this, "Please install a File Manager.",
                            Toast.LENGTH_SHORT).show();
                }

            }

           else if(Build.VERSION.SDK_INT >= 19){
                intent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE,true);
                intent.putExtra(Intent.EXTRA_LOCAL_ONLY,true);
                intent.setAction(Intent.ACTION_PICK);

                try {
                    startActivityForResult(
                            Intent.createChooser(intent, "Select Picture"),FILE_SELECT_CODE);
                } catch (ActivityNotFoundException ex) {
                    // Potentially direct the user to the Market with a Dialog
                    Toast.makeText(this, "Please install a File Manager.",
                            Toast.LENGTH_SHORT).show();
                }
            }

           else {
               Log.e("no","no");
            }

}

i want to show it like this

Thank you.

1

There are 1 best solutions below

2
Sagar gujarati On

Try this :

if (Build.VERSION.SDK_INT >= 23) {
                    if (checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
                        requestPermissions(new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, 101);
                    } else {
                        Intent intent = new Intent();
                        intent.setType("image/*");
                        intent.setAction("android.intent.action.PICK");
                        startActivityForResult(Intent.createChooser(intent, "Select picture using"), 101);
                    }
                } else {
                    Intent intent = new Intent();
                    intent.setType("image/*");
                    intent.setAction("android.intent.action.PICK");
                    startActivityForResult(Intent.createChooser(intent, "Select picture using"), 101);
                }

if you want a list of folder then you can use one of this lib

https://github.com/topics/android-image-picker