Reputation: 44
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);
}
}
}
I want to add internal and external storage like this to file chooser
Upvotes: 2
Views: 5385
Reputation: 1017
you must use Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT_TREE);
insted Intent intent = new Intent(Intent.ACTION_GET_CONTENT );
Upvotes: 0
Reputation: 1006819
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.
Upvotes: 3