Hello I am trying to create a picture and save it into one directory of the SD card programmatically but when I go to gallery then these picture doesn't show there. It shows when I open any SD card browser app.
Is there any way to force so that picture appear in Gallery App also at the same time when I am saving the picture in my directory.
Thanks in advance.
The system does not scan the disk content all the time, it would kill the performances.
When you add a picture that the Gallery needs to pick-up, use
Intent intent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
intent.setData(Uri.fromFile(file));
sendBroadcast(intent);
This will allow the mediaScanner to have a look at the file immediately.
Note : if the file is incorrect for some reason, it will not have any effect.
Related
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.
My app has a built-in cropper. I want the user to select photos from the Gallery but only folders that are on the phone. By default, the Gallery shows all folders including those from PicasaWeb.
Thanks in advance.
You need to add an extra to your intent.
intent.putExtra(Intent.EXTRA_LOCAL_ONLY, true);
Android image picker for local files only
The device is Samsung Galaxy III. I developed an APP to run the camera activity and capture an image. After analyzing the image, I print out some text information. Right now every captured image is saved at gallery. I don't need the image to be saved in gallery or SD card. I think either of the following two solutions will work for me, but I don't know how to program it:
avoid saving pictures to gallery.
delete the picture somewhere in the APP.
Any comments are appreciated.
Read Android Camera tutorial.
...
Storage - Are the images or videos your application generates intended to be only visible to your application or shared so that other applications such as Gallery or other media and social apps can use them? Do you want the pictures and videos to be available even if your application is uninstalled? Check out the Saving Media Files section to see how to implement these options.
or see this one: How to save image captured with camera in specific folder.
In the Camera intent when starting, add this:
intent.putExtra(MediaStore.EXTRA_OUTPUT,Uri.fromFile(getTempFile(context)));
I solved my problem with following two steps:
as '#auselen' pointed, save all the images to a specific folder. How to save image captured with camera in specific folder.
delete all the images in that folder somewhere in the APP. How to Delete Image From SDCard in Android
use this for delete a pic
ImgPhoto1.setImageBitmap(null);
I have between one and three photos I'd like my app to display. I won't know until runtime exactly how many photos are downloaded from the Internet.
I can't figure out how to create an Intent to display the photos. Right now I'm caching them on the sdcard under a folder I create by doing something like (sans error checking):
final File externalDirectory = Environment.getExternalStorageDirectory();
final String folder = externalDirectory.getAbsolutePath() + "/Android/data/" + packageName + "/files/";
This was explained in the Android Developer Reference.
I can get one photo to display by doing the following:
final Uri uri = Uri.fromFile(file);
final Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(uri, "image/*");
Util.startActivity(this, intent);
Where file is the file of a saved photo.
If it helps, I could save the images to any location available to my app, however I would prefer to not have the photos show up listed with the user's other personal photos as that may be annoying.
The Image Viewer has a menu option "Slideshow", so it must know about multiple photos.
I could create my own Image Viewer, but that seems like extra work and beyond what I would I reasonably expect. Even if I did this, I would like the user to be able to install a 3rd party Image Viewer and get a better experience with pan, zoom, share, ...
I tried using the directory of the cached photo files to create the Uri, but the Image Viewer shows a black page. If I pass in the file, it shows just that one file and no others.
I know this must be possible because I can see use the Gallery app and show the photos if I manually select the folder. Everytime I research this issue, the comments say it's not possible to show multiple images.
I suspect there's some magic incantation, but what?
I think your goal is out of your control. If the viewer app is designed to handle mutiple images or a directory, you may ask it to show as you want, but you are defined to the viewer's pattern.
I have installed a third-party image viewer called QuickPic. I just tested your code snippet and the system popped up a chooser dialog to let me select the app to show the images in the folder. If I select native gallery, what I see is just an empty folder, while the Quickpic works as I want.
PS: I tell my app the Uri of the folder this way:
intent.setDataAndType(Uri.fromFile(new File("//mnt/sdcard/test/")), MimeTypeMap.getSingleton().getMimeTypeFromExtension("png"));