Search code examples
androidandroid-intentandroid-activityfilechooserandroid-afilechooser

How to add Internal and External storage to File Chooser in android


My sample app is open file chooser and select file / directory then getting the path into EditText, I tried the methods in this question and I reached to this result

    public class MainActivity extends AppCompatActivity {
    private Button browse;
    private EditText editTextPath;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        browse = (Button) findViewById(R.id.browse);
        editTextPath = (EditText) findViewById(R.id.path);
        browse.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
                intent.setType("*/*");
                intent.addCategory(Intent.CATEGORY_OPENABLE);
                startActivityForResult(Intent.createChooser(intent,"Select file or dir"), 1);
                setResult(Activity.RESULT_OK);
            }
        });


    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode == 1 && resultCode == Activity.RESULT_OK) {
            String Fpath = data.getDataString();
            editTextPath.setText(Fpath);
        }

    }
}

AndroidFileChooser

I want to add internal and external storage like this to file chooser

AndroidFileChooser2


Solution

  • The user can tap the "..." affordance in the action bar and choose "Show internal storage" to display those options.

    There is no official support for anything on ACTION_GET_CONTENT or ACTION_OPEN_DOCUMENT to show internal storage options automatically, though hopefully this will be supported someday.