Android SDK - Link to the phone gallery app?

As of now, in my application I created a small gallery application using the provided widget, I need this to select a picture from the phone. This works great and that’s all, but the presentation is lacking.

I have several applications on my phone that do the same, but they somehow use a gallery that already on the phone allows the user to select an image. For example, FourSquare, when you select an image to use as an image, loads a gallery and asks you to select an image.

How is this possible? I surfed the Internet for the last couple and came up empty-handed.

+4
source share
1 answer

To get an image from the standard gallery, you can:

private static final int MEDIA_IMAGE_REQUEST_CODE = 203948; // This can be any unique number you like Intent getImageFromGalleryIntent = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.INTERNAL_CONTENT_URI); startActivityForResult(getImageFromGalleryIntent, MEDIA_IMAGE_REQUEST_CODE); 

Then, to get the image as soon as the user selects one of them:

 protected final void onActivityResult(final int requestCode, final int resultCode, final Intent i) { super.onActivityResult(requestCode, resultCode, i); if(resultCode == RESULT_OK) { switch(requestCode) { case MEDIA_IMAGE_REQUEST_CODE: // Get the chosen images Uri Uri imageUri = i.getData(); // Load the bitmap data from the Uri // It is probably best to do this in an AsyncTask to avoid clogging up the Main Thread break; } } 
+5
source

Source: https://habr.com/ru/post/1311632/


All Articles