3

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
  • 535
  • 7
  • 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
  • 954,112
  • 185
  • 2,315
  • 2,367
  • 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
0

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

mostafa3dmax
  • 890
  • 6
  • 18