How to allow user to use my app?

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

Was this solution helpful to you?

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:

Just Added Q & A:

Find solution

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.