0

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.

Markus Kauppinen
  • 3,025
  • 4
  • 20
  • 30
CHAMI
  • 31
  • 1
  • 8

1 Answers1

1

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

Sagar gujarati
  • 152
  • 1
  • 15
  • hi @sagar thank for your answer,but its' not that i expected ... i want to show only image folder and and file folder – CHAMI Nov 08 '19 at 05:43
  • Then you need to create custom gallery in your app if you want to see all of the folder of images from storage – Sagar gujarati Nov 08 '19 at 05:57