2

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

MML
  • 44
  • 1
  • 8
  • 21
  • 2
    This is the Lolipop dialog, and now changed to a newer version and Google Drive also supported. https://metactrl.com/docs/sdcard-on-lollipop/ – matio Jan 16 '18 at 21:54
  • @matio thank you It has now appeared, not I want to get full path in Edit Text because this code not getting logical path see this image https://i.imgur.com/PkakUbn.png – MML Jan 16 '18 at 22:04
  • If this is your answer accept it as "This comment adds something useful " along the comment. Then create another thread with what you want and I'l be help there. – matio Jan 16 '18 at 22:38

2 Answers2

3

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.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • but I see this options in some apps appearing internal and external "SD card like this
    – MML Jan 16 '18 at 21:35
  • 3
    @MML: Presumably, [they are not playing by the rules](https://issuetracker.google.com/issues/72053350). – CommonsWare Jan 16 '18 at 21:47
  • 1
    Why not add that to your answer, it's far more useful than just "There is no official support for (it)" – Tim Rae Oct 09 '18 at 13:36
  • @TimRae: Because until it is officially supported (and hopefully becomes part of the CTS), it is unreliable. – CommonsWare Oct 09 '18 at 21:50
  • Say, how do I offer my own content to be available for the user on this UI of the file picker (on the navigation drawer on the left) ? – android developer Jan 20 '23 at 12:12
  • 1
    @androiddeveloper: You would need to implement [a `DocumentsProvider`](https://developer.android.com/reference/android/provider/DocumentsProvider). – CommonsWare Jan 20 '23 at 12:42
  • @CommonsWare Thank you. Is there a tiny sample for this somewhere? – android developer Jan 20 '23 at 20:48
  • @androiddeveloper: I doubt it can be all that tiny, given that it's a verbose API. But, there is https://medium.com/androiddevelopers/building-a-documentsprovider-f7f2fb38e86a. And there is [Vault](https://android.googlesource.com/platform/development/+/android-5.0.0_r2/samples/Vault/src/com/example/android/vault/VaultProvider.java), though you might see if there is a newer version than that one. – CommonsWare Jan 20 '23 at 21:07
  • @CommonsWare I don't mind that it even shares content within the app. I learn better by samples, and the smaller the sample, the easier it is for me to go further. Sadly almost all of Google's samples tend to be the complete opposite of simple. Anyway thanks. Please if you find anything, let me know. – android developer Jan 20 '23 at 22:36
0

you must use Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT_TREE); insted Intent intent = new Intent(Intent.ACTION_GET_CONTENT );

mostafa3dmax
  • 997
  • 7
  • 18