taormania
taormania

Reputation: 671

Android SDK: Let user choose picture from gallery or camera?

In my project I want to let the user pick a picture either from the gallery or take a new one from the camera. Do I need to create my own menu for the user to choose or is there something built into the SDK that does this already?

Upvotes: 2

Views: 2700

Answers (1)

nandeesh
nandeesh

Reputation: 24820

Use the below code to put chooser for gallery and Camera together. I really dont know if this will work with startActivityForResult. Give it a try

    Intent galleryintent = new Intent(Intent.ACTION_GET_CONTENT, null);
    galleryintent.setType("image/*");        

    Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);

    Intent chooser = new Intent(Intent.ACTION_CHOOSER);
    chooser.putExtra(Intent.EXTRA_INTENT, galleryintent);      
    chooser.putExtra(Intent.EXTRA_TITLE, "title");

    Intent[] intentArray =  {cameraIntent}; 
    chooser.putExtra(Intent.EXTRA_INITIAL_INTENTS, intentArray);
    startActivity(chooser);

Upvotes: 3

Related Questions