Is there a method that needs to be called to notify the OS that a new image has been added to the photo gallery?
I've got a camera application that allows a user to export images to a sub folder in the Android device's photo gallery.
The copy functionality works properly, but it can sometimes take anywhere from 10 seconds to 2 minutes for the gallery app to recognize that a new image has been added to the folder. And sometimes I need to exit the application, then return before it displays the new image. The behavior is the same whether I use the Samsung Gallery app or the Google photos app, which suggests it is an OS level cache.
I've verified the image is being written immediately within the device browser in Android studio.
You can add the current item to the OS's cache by using the following code:
// Add the file to the media database
var f = new Java.IO.File(fileInTargetDirectory);
var intent = new Intent(Intent.ActionMediaScannerScanFile);
intent.SetData(Android.Net.Uri.FromFile(f));
CrossCurrentActivity.Current.Activity.SendBroadcast(intent);
Related
My flutter app is successfully downloading media to 'android/media/com.example.testapp/testapp/images/'. I can see them via file explorer but for some reason I am not able to see them in gallery. Earlier I was storing images outside of the android storage at that time Images were showing in gallery. I'm using mediascanner for this.
print(directory.path);//outputs /storage/emulated/0/Android/media/com.example.testapp/testapp/images/image1.jpg
MediaScanner.loadMedia(path: directory.path);
I think the problem is that, you aren't telling the OS about new image or video, for this you need to use Android Intent or use this plugin https://pub.dev/packages/image_gallery_saver, it will update the media files every time you save your file using this plugin
I'm using multi_image_picker to allow picking images in my Flutter app.
I've noticed odd behavior when I download an image and store in the Download folder of the device, and the following things happen:
After I download an image, I trigger the image picker (by running MultiImagePicker.pickImages).
Image Picker doesn't show the image, which is odd since I've downloaded the image.
I'm navigating to the Android Files app and I do find the image.
Restarting my app and navigating again to the Image Picker, but still - image not exists.
Opening Google Photos app and after a second the image appears.
Navigating back to my app -> Image Picker, and then I see the image.
I know it sounds odd. I have no idea how or why it happens. I'm using Flutter 1.10.3 and a fresh Android API 28 emulator. I ran the app in an Android Q too and the results are the same.
Looks like your download directory and your GooglePhotos sync directory are in two different places and MultiImage.pickImages is looking at the GooglePhotosSync directory (which might also be the devices CameraRoll directory).
So you are dependent on GooglePhotos uploading the photo from one place and downloading it to another.
Most of my work is ios so sorry I cant be more specific.
I observed similar behavior in terms of some photos not showing when picking image from gallery.
I just found the cause 5 minutes ago before asking "Have you found out the solution?"
It turns out, the flutter image pickter starts from "Recent" folder, the photos I have recently downloaded have much older timestamp. So these photos are futher down in the list.
I will look into a solution.
I am developing application for TomTom navigation (Android 4.3). In my app I take some pictures and save them to some folder (external storage). When I want to edit the picture, I call the following piece of code:
Intent editIntent = new Intent(Intent.ActionEdit);
string currUri = ((ImageAdapter)gallery.Adapter).currURI;
editIntent.SetDataAndType(Android.Net.Uri.Parse(currUri), "image/*");
editIntent.SetFlags (ActivityFlags.GrantReadUriPermission);
StartActivityForResult(editIntent, 1);
This opens the default android gallery where I can process my picture. After that I click on Save button and the gallery app shows dialog :"Saving picture to edited online photos" and then the gallery crashes.
When I tried it on another device (API 19), it worked great and saved the picture to the same folder as original picure. Why does the gallery try to save edited picture to the folder called "EditedOnlinePhotos" on API 18? Is there any differnce in API 19?
This is the device log at the moment the app crashes:
device log
I spent a lot of time on it, however I was not able to solve it.
If you have any idea or need more information, feel free to reply. Thank you, I appreciate your help.
I am new to Android. This is my first question. I am testing on 4.4.4, KitKat.
I am using the Android Developers "Taking Photos Simply" code in my app.
(Taking Photos Simply Tutorial)
I want the photos taken by the user to be available to my app, but also available later in the gallery.
If I specify
File storageDir = getExternalFilesDir (null);
Then various cameras work (camera, opencamera, DSLR camera), but after I leave my app the images do not appear in the gallery.
If I specify
File storageDir = Environment.getExternalStoragePublicDirectory(
Environment.DIRECTORY_PICTURES);
Then the behavior is the same, except for one camera app: DSLR Camera. The photo does appear in that app's camera directory which is visible using the gallery later.
I want this behavior for my app. I want the photos that the user takes to appear in a directory that they can later see using the gallery app. I don't want to create duplicate images, however.
I also want to save modified images later on to the same directory.
Thanks for any help
but after I leave my app the images do not appear in the gallery.
It may eventually. Gallery apps usually use the MediaStore, and your file may eventually be added to it. Use MediaScannerConnection and scanFile() to expedite this process.
You need to request the media scanner to scan a file and add it to the media database.Use this code.
Intent mediaScanIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
mediaScanIntent.setData(mMediaUri);
sendBroadcast(mediaScanIntent);
and see ACTION_MEDIA_SCANNER_SCAN_FILE in android developer site.Here mMediaUri is the Uri of your file.
I am new to Android and now trying to retrieve contact photo (thumb nail) from a content provider and set it onto my app. But for that as i am running on an AVD, i pushed some .png photos onto my 2.2 version. Now i tried to create a contact with the photo, but the Gallery is showing "No Media Found", hence i am stuck here.
Please help me in getting the photo visible in gallery.
Note : I am aware of the following facts :
I have restarted my AVD to force the Media Scanner to do its initial mockups.
Also i have seen the .png file through the File Explorer View of Eclipse Framework.
But strangely, I am not able to pull the file off the phone.
I have taken help of the link get the path of a Gallery Folder in Android for understanding the general view on Media Scanner.
I believe this is because the application doesn't know if there are images inside /data.
Try to put your images in:
/mnt/sdcard/Pictures