Grab photo from android gallery directly

Asked

Viewed 2,550 times

1

I’ve searched here and other places on the Internet, but I haven’t been able to locate anything like it. Is it possible to restrict that photos selected by a user only come from the gallery? Ex: When I click on a profile photo and choose the gallery option I be directed directly to the photos that are in the gallery and select any one.

1 answer

3


Try the following:

Open option:

 public static final int PICK_IMAGE = 1234;
 Intent i = new Intent(Intent.ACTION_PICK,
            android.provider.MediaStore.Images.Media.INTERNAL_CONTENT_URI);
    startActivityForResult(Intent.createChooser(i, "Selecione uma imagem"), PICK_IMAGE);

Reception of the image in Activity:

 @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        if(resultCode != Activity.RESULT_CANCELED){
            if(requestCode == PICK_IMAGE){
                Uri selectedImage = data.getData();
                Toast.makeText(getApplicationContext(), selectedImage.toString(), Toast.LENGTH_SHORT).show();
            }
        }
    }
  • Thiago’s answer is correct, so the gallery opens directly. Question solved.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.