2

I'm trying to make an app with Android Studio that can select a file in SD card and get its path, like an OpenFileDialog, I've tried this:

Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("file/*");
startActivityForResult(intent, PICKFILE_REQUEST_CODE);

However, it does not work, how can I do it ?

lmiguelvargasf
  • 63,191
  • 45
  • 217
  • 228
MH. Abdi
  • 298
  • 5
  • 22

1 Answers1

0

Try this:

  Intent mediaIntent = new Intent(Intent.ACTION_GET_CONTENT);
  mediaIntent.setType("*/*"); //set mime type as per requirement
  startActivityForResult(mediaIntent,0);

You can change type according to your need.

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    // TODO Auto-generated method stub
    super.onActivityResult(requestCode, resultCode, data);
    if (requestCode == 0
            && resultCode == Activity.RESULT_OK) {
        Uri uri = data.getData();
       Log.d("", "Video URI= " + videoUri);

    }
 }
Sonam Gupta
  • 341
  • 1
  • 12