Skip to content

Instantly share code, notes, and snippets.

@webserveis
Created July 20, 2016 09:35
Show Gist options
  • Save webserveis/2a03f1f34dcfd2a23cd3f789295c3bf1 to your computer and use it in GitHub Desktop.
Save webserveis/2a03f1f34dcfd2a23cd3f789295c3bf1 to your computer and use it in GitHub Desktop.
Launch file chooser selector dialog
private static final int FILE_CHOOSER = 100;
...
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("*/*");
startActivityForResult(Intent.createChooser(intent, "Choose File"), FILE_CHOOSER);
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
switch (requestCode) {
case FILE_CHOOSER:
Log.d(TAG, "onActivityResult: FILE_CHOOSER =" + FILE_CHOOSER);
if (resultCode == RESULT_OK) {
Uri uri = data.getData(); //obtener el uri content
Log.d(TAG, "uri: " + uri.toString());
} else {
//if (resultCode == RESULT_CANCELED) {
Log.w(TAG, "Cancel by user");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment