How to open a dialog to search a file on Android? A Filedialog

Asked

Viewed 327 times

0

My question is about opening files in my Android application, how to upload image from mobile to the server where I first need to choose the image on my mobile. I’d like to know what I need to use to open one FileDialog, as in C# if I’m not mistaken, in Android to choose an image file or text that is and load it in my application so I can work with it (Send, Modify anyway).

1 answer

2


You can use this code that will return the URI of the image selected by Picker. Then you can use this Uri to upload the image or send it somewhere else.

Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent, "Select Picture"), PICK_IMAGE);
  • Man, sensational, I didn’t think it was that simple. Interesting here is that I can restrict users from choosing only the file types I want. For example: intent.setType("text/*"); for files . txt or intent.setType("*/*"); for all aquives

Browser other questions tagged

You are not signed in. Login or sign up in order to post.