Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to open phones gallery through code

Tags:

I wanna to open phones gallery through a button click.
In my activity I have a button, I want to open the gallery through that button click.

like image 697
Jyosna Avatar asked May 16 '11 10:05

Jyosna


People also ask

How can I open gallery programmatically in Android?

To open gallery: (This should be in your activity class.) public OnClickListener btnChoosePhotoPressed = new OnClickListener() { @Override public void onClick(View v) { Intent i = new Intent(Intent. ACTION_PICK, android. provider.

Which button is used to open gallery?

1. You can open the Gallery panel by clicking the Gallery button on the Sidebar (True/False). 2.


1 Answers

Here is sample code for open gallery from app.

Intent intent = new Intent(); intent.setType("image/*"); intent.setAction(Intent.ACTION_GET_CONTENT); startActivityForResult(Intent.createChooser(intent, "Select Picture"),SELECT_IMAGE); 

OnActivityResult for get image.

public void onActivityResult(int requestCode, int resultCode, Intent data) {     super.onActivityResult(requestCode, resultCode, data);     if (requestCode == SELECT_IMAGE) {         if (resultCode == Activity.RESULT_OK) {             if (data != null) {                 try {                     Bitmap bitmap = MediaStore.Images.Media.getBitmap(getActivity().getContentResolver(), data.getData());                 } catch (IOException e) {                     e.printStackTrace();                 }             }         } else if (resultCode == Activity.RESULT_CANCELED)  {             Toast.makeText(getActivity(), "Canceled", Toast.LENGTH_SHORT).show();         }     } } 
like image 104
Niranj Patel Avatar answered Dec 23 '22 07:12

Niranj Patel