I need to display the images that are in a specific folder on the SD card.
I want to do it with a button and display the gallery. But, I don't know how to do it. I found some solution like this, but that solution didn't work for me:
public void openFolder(View view)
{
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
Uri uri = Uri.parse(Environment.getExternalStorageDirectory().getPath()
+"/pictures/miscursos/");
intent.setDataAndType(uri, "image/jpeg");
startActivity(Intent.createChooser(intent, "Open folder"));
}
This just opens all the images, but not the folder that I want.
The above code will only opens the folder. You have to use GallerView or GridView with the help of Adapter you can set images to ListView or GridView. You have to give correct path in-order to open the folder you want.
GridView loading photos from SD Card - refer this link
Related
I am new to android development.
I am trying to open the default gallery app to view an image like this:
Uri u = Uri.parse((String) gridView.getAdapter().getItem(position);
Intent i = new Intent();
i.setDataAndType(u, "image/*");
i.setAction(Intent.ACTION_VIEW);
i.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
startActivity(i);
I provide the file paths to my images like this:
/storage/emulated/0/WhatsApp/Media/WhatsApp Images/IMG-20191023-WA0045.jpg
/storage/emulated/0/Pictures/9GAG/1565987862000.jpg
My App and Google Photos can display the image given this path, the Samsung Gallery( tested on Android Oreo) or the Xiaomi Gallery App (tested on Android X) can't find the image; also if i try to add "content://" or "file://" at the beginning.
I suspect that the apps want to have a Content URI or some kind of symbolic link without the "/storage/emulated/0/" part instead of a File URI. I searched for methods to get the content URI out of the file path, but didn't find any examples for Android X.
So what is the correct URI to pass on through the Intent and how do i get it?
Or maybe somebody knows a better way to just open the gallery app to a specific picture i provide by an absolute file path (Both External Storage and SD Card)?
Thank you in advance and greetings!
copied from this question here , this might work for you
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("content://media/external/images/media/16"))); /** replace with your own uri */
My application is capable of capturing images and saving them (in the public Pictures directory, retrieved by Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES).
Now, I want to be able to display those images in the system's gallery application. In order to achieve that, I create an Intent like this (filePath is a String containing the image's path):
Intent viewIntent = new Intent();
viewIntent.setAction(Intent.ACTION_VIEW);
Uri uri = Uri.fromFile(new File(filePath));
viewIntent.setDataAndType(uri, "image/jpeg");
startActivity(Intent.createChooser(viewIntent, null));
Displaying an image this way works perfectly fine, but the gallery's Share functionality doesn't seem to work:
When I press the Share-button, I get to choose the app I want to share to; but once I select it, nothing happens, as if the target application does not receive any data.
Is there any explanation why this behaviour occurs and how it can be fixed?
Edit: I used Intent Intercept to capture the Intent created by the Gallery/Photos app:
I am using list view and gallery in android.. i have 3 views as list items i.e a contact photo,name and a button to add that contact . when user clicks the button inside list view,the contact photo of that items should add in gallery... Can anybody please tell how to achieve this?
#Nidhi can you add image like that
private void addPicToGallery() {
Intent media = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
//mCurrentPhotoPath is the path to image.
File f = new File(mCurrentPhotoPath);
Uri contentUri = Uri.fromFile(f);
media.setData(contentUri);
this.sendBroadcast(media);
}
save image in sdcard. But after this, you will not be able to see that image in gallery. To see this image, You will have to refresh sdcard using
broadcast(sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED,
Uri.parse("file://" + Environment.getExternalStorageDirectory().getAbsolutePath())));)
when you will save this image.
If my understanding is correct, Why can't you just download the image and save them in sd card? It will show up in gallery automatically. if it is not showing in gallery you can call the following to call implicitly after downloading the images to sd card.
sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED,
Uri.parse("file://" + Environment.getExternalStorageDirectory())));
I'm trying to open all the photos taken with my app using the native Gallery.
Here is my code:
Intent intentBrowseFiles = new Intent(Intent.ACTION_VIEW);
intentBrowseFiles.setType("image/*");
Uri uri = Uri.parse(Environment.getExternalStorageDirectory() + "/DCIM/MyApp");
intentBrowseFiles.setData(uri);
intentBrowseFiles.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intentBrowseFiles);
If I don't set the setData the gallery opens, but in the root, if I set, my app crashes.
Is there a way to open it in the Gallery in a specific directory?
Anyway, thank you!
I have to include an image picker in my android app.
I set it like this :
Intent intentGallery = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(intentGallery, 0);
But all the pictures of the SD card are displayed. I only want to show the pictures taken with the camera (in the DCIM folder).
Is it possible to do that ?
No, it is not possible.
If necessary, you can implement your own gallery, that will pick images only from
android.provider.MediaStore.Images.Media.INTERNAL_CONTENT_URI
and
android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI
You would use android.provider.MediaStore.Images.Media.INTERNAL_CONTENT_URI to access images on the device instead of the SD card.
[EDIT]
Browsing the Android source, specifically the Gallery app, I stumbled across
public static final String CAMERA_IMAGE_BUCKET_NAME = Environment.getExternalStorageDirectory().toString() + "/DCIM/Camera";
Which I guess is what you are looking for. You can view the full source here