How do I allow a user to browse/choose a file for my app use in Android?
-
I have an app where the user can choose a profile pic using images stored on the phone or SD. Do I have to write my own file explorer for this? I've seen a couple examples on anddev, but wasn't sure if there is another way. Thanks.
-
Answer:
Use Intent.ACTION_GET_CONTENT to launch an activity for the user to select the desired media type. For selecting an image, you would probably want the MIME type of "image/*". You also want to wrap this in a choose since often there will be multiple content sources for the user to select from (for example they could browse through the gallery, or could take a picture at that point, or a generic file browser if one is installed, etc). Here is some rough code, probably buggy because I am just writing it out here: Intent intent = new Intent(Intent.ACTION_GET_CONTENT); intent.setType("image/*"); // Do this if you need to be able to open the returned URI as a stream // (for example here to read the image data). intent.addCategory(Intent.CATEGORY_OPENABLE); Intent finalIntent = Intent.createChooser(intent, "Select profile picture"); startActivityForResult(finalIntent, IMAGE_SELECTED); When the user has selected something, you will get the selection back in onActivityResult(). More reference: http://developer.android.com/reference/android/content/Intent.html#ACTION_GET_CONTENT
Jim D. at Stack Overflow Visit the source
Other answers
The http://www.openintents.org/en/node/159 control is one excellent solution The OpenIntents file manager allows you to browse your SD card, create directories, rename, move, and delete files. It also acts as an extension to other applications to display "Open" and "Save" dialogs.
jspcal
Related Q & A:
- How do I convert a PDF file to PDF/A in Delphi?Best solution by softwarerecs.stackexchange.com
- How do I send a message from yahoo to a cell phone?Best solution by Yahoo! Answers
- How do I upload a picture instead of using a generic avatar?Best solution by answers.yahoo.com
- How do i make a my yahoo but not a home page?Best solution by Yahoo! Answers
- How do I connect a laptop running XP to a wireless HP printer?Best solution by Yahoo! Answers
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.