César Castro Aroche César Castro Aroche - 1 year ago 125
Java Question

Get address from file explorer Android

I'm making a program that asks the user to find a file which could be stored on the sdcard or the internal card of the phone. I know that in order to open the default file explorer in the phone I must use this code:

Intent intent = new Intent();

However, my problem is related with the communication with the File Explorer, how can I get the address of the file the user selected.

Answer Source
    Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
    startActivityForResult(intent, YOUR_REQUEST_CODE);

protected void onActivityResult(int requestCode, int resultCode, Intent data) {
  if (resultCode == RESULT_OK) {
    switch (requestCode) {
      //get the uri from data's extras
     //do whatever you want with uri
  } else {
    Toast.makeText(this, "Wrong result", Toast.LENGTH_SHORT).show();
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download