-1

I'd like to have a button in my app that when pressed, the user is taken to the phones built-in gallery app. And if possible, I'd like the user to be taken to the directory that the app creates. Is there a way to do this in Android? It's alright if the app ends after they go into the gallery.

user1657178
  • 21
  • 1
  • 5
  • make an intent that take you to the gallery.with onlick event – Giant Jul 26 '13 at 02:21
  • 2
    Duplicate - [How to open phones gallery through code](http://stackoverflow.com/questions/6016000/how-to-open-phones-gallery-through-code) – neo108 Jul 26 '13 at 03:14

2 Answers2

0

Try This Codes...!

Button btn = (Button) findViewById(R.id.btn);

btn.setOnClickListener(new OnClickListener()
{
    @Override
    public void onClick(View v) {
        // TODO Auto-generated method stub

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

    }
}); 
Hariharan
  • 24,741
  • 6
  • 50
  • 54
0

You can use intent to use defalut Gallery in android and here the code is-

Button GalleryButton=(Button)this.findViewById(R.id.galleryview); GalleryButton.setOnClickListener(new OnClickListener() {

    public void onClick(View arg0) {

        // in onCreate or any event where your want the user to
        // select a file
        Intent intent = new Intent();
        intent.setType("image/*");
        intent.setAction(Intent.ACTION_GET_CONTENT);
        startActivityForResult(Intent.createChooser(intent,
                "Select Picture"), SELECT_PICTURE);
    }
});

}

public void onActivityResult(int requestCode, int resultCode, Intent data) {
        if (resultCode == RESULT_OK) {
            if (requestCode == SELECT_PICTURE) {
                Uri selectedImageUri = data.getData();
                filemanagerstring = selectedImageUri.getPath();
                selectedImagePath = getPath(selectedImageUri);

                if(selectedImagePath!=null)
                    System.out.println(selectedImagePath);
                else System.out.println("selectedImagePath is null");
                if(filemanagerstring!=null)
                    System.out.println(filemanagerstring);
                else System.out.println("filemanagerstring is null");

                if(selectedImagePath!=null)
                    System.out.println("selectedImagePath is the right one for you!");
                else
                    System.out.println("filemanagerstring is the right one for you!");
            }
        }
    }

    public String getPath(Uri uri) {
        String[] projection = { MediaStore.Images.Media.DATA };
        Cursor cursor = managedQuery(uri, projection, null, null, null);
        if(cursor!=null)
        {
            int column_index = cursor
            .getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
            cursor.moveToFirst();
            return cursor.getString(column_index);
        }
        else return null;
    }
Ravi
  • 2,277
  • 3
  • 22
  • 37