I want to show the different pictures a user has in their phone like whats app does in cards from all the albums/folders the user has in their gallery in cards (ex: whats app images, downloads, all photos, etc..). And when the user clicks the card, it shows all the images in that folder in cards too. Can someone please tell me how to access the folders since that is the main issue?
Asked
Active
Viewed 328 times
0
-
Does this answer your question? [android pick images from gallery](https://stackoverflow.com/questions/5309190/android-pick-images-from-gallery) – happyvirus Jun 23 '20 at 11:12
2 Answers
0
You can try something like this:
private static final int PICKFILE_RESULT_CODE = 1;
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(
Intent.createChooser(
intent,
"Select Image from here..."),
PICKFILE_RESULT_CODE);
Using this you can make the user to navigate to gallery and select images.

S M Vaidhyanathan
- 320
- 1
- 4
- 13
0
What WhatsApp does is that it starts an Intent that calls the default gallery Application installed the user's phone. As stated in another answer, you need to start a gallery intent in which you can only have Images shown to the user. This Intent returns a code which tells the application that launched the intent whether the file picking was successful or not, based on that result you can modify your code. Here's an Example:-
Intent openFileManager = new Intent(Intent.ACTION_GET_CONTENT); //For Chosing to Open the file manager
openFileManager.setType("image/*"); //for telling the file manager that only files of type image should be returned
startActivityForResult(openFileManager, 12); //starting the intent, here 12 is the code that tells whether it was successful or not
For dealing with what result the user has picked:-
@Override
public void onActivityResult(int requestCode, int resultCode, @Nullable Intent data)
{
if(requestCode == 12 && resultCode == RESULT_OK) //requestCode tells which intent to look for and resultCode tells whether the result is okay or not
{
//Your Code goes here
//The file which has been returned is in the Intent, you can get that file from Intent "data"
}
else
{
super.onActivityResult(requestCode, resultCode, data);
}
}

Sampurna
- 205
- 2
- 9