Android picture saved to SD card not showing in Gallery - android

Currently I have a program that takes pictures and saves them as a jpg on the top level of the sdcard, but its not appearing in the Gallery. Is there something I must do to make it happen?

You need to call the MediaScanner so that it knows your file exists:
File file; // = your file
String mimetype; // = your file's mimetype. MimeTypeMap may be useful.
MediaScanner.scanFile(getApplicationContext(), new String[]{file.getPath()}, new String[]{mimetype}, null);

Try this answer. Working for me
context.sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, Uri.fromFile(finalFile)));

Maybe someone is "overseeing" it...
Take a look at:
https://stackoverflow.com/a/5110571/371749

Related

Mediastore scan does not notice mp3 album artwork tagging

My code behavior changes at the artwork for a single MP3 file. By opening the MP3 file on my PC the artwork got changed but by opening the MP3 file on the android device nothing happens. The shown artwork is still the old one.
I tried this:
Intent mediaScanIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
File f = new File(song_path);
Uri contentUri = Uri.fromFile(f);
mediaScanIntent.setData(contentUri);
FindCoverActivity.this.sendBroadcast(mediaScanIntent);
but nothing happend.
I tried another thing: By changing the artwork AND the name of the album the mediastore immediatly noticed what was going on and by opening the mp3 file on the android phone again, the artwork gets displayed correctly with the new artwork. But it is not my goal to change important mp3 tags like the album name. Could this be a bug or has anyone suggestions?
Thanks!
You could try MediaScannerConnection and its scanFile() method instead of ACTION_MEDIA_SCANNER_SCAN_FILE and see if you have better results.
Also, make sure that the file's last-modified timestamp is changed when you save your modified artwork. I'm not an expert at such MP3 file modifications, but if there is a timestamp tag in there, you might consider updating that timestamp as well. Basically, you need to make sure that the MediaStore realizes that there is a change that requires an update of its metadata.
If all else fails, you could try to work out an approach that temporarily modifies the album name in a minor fashion (e.g., appends a space), then changes it back. This is a hack, but it may be your only reliable option.

Take a screenshot android (continue)

first of all sorry.. but i cant answer in
Android take screen shot programmatically cause dont have enought reputation.
The code works fine! thanks.. but.. when i take the screenshot.. the file is stored in the root folder
String extr = Environment.getExternalStorageDirectory().toString();
File myPath = new File(extr, getString(R.string.tituloAplicacion)+".jpg");
but also appears in the Camera DCM folder with another name, its possible avoid that?
Thanks

not always getting the right image

I have a custom camera that has a public method for getting the thumbnail of that last image saved to a specific folder on the sdcard...
that method looks like this:
public void getGalleryThumb(){
// TODO add Logic for gallery images..
File sdDir = new File("/sdcard/LC/images");
File[] sdDirFiles = sdDir.listFiles();
if(sdDir.length()>0){
File lastPhoto = sdDirFiles[0];
Bitmap myBitmap = BitmapFactory.decodeFile(lastPhoto.getAbsolutePath());
//SET MY IMAGE VIEW BITMAP TO LAST FILE IN sdDIRFiles
photo.setImageBitmap(myBitmap);
btn_gallery.setVisibility(View.VISIBLE);
}
//Toast.makeText(getBaseContext(), "num images in gal:"+sdDirFiles.length +"last image name: "+sdDirFiles[0], Toast.LENGTH_LONG).show();
}
i have noticed that if i delete a photo from that folder the method above does not always retrieve the right image.. I have used:
sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED,
Uri.parse("file://"+ Environment.getExternalStorageDirectory()+"/LC/images/")));
upon deleting and writing new files to that sdcard/folder but it doesn't seem to do the trick plus it forces this annoying toast message about the sdcard being mounted..
any help would be appreciated
I was writing this in a comment, but I'll put the detail here. Multiple issues:
listFiles doesn't not guarantee order. You'll need to sort your files by last modified.
You shouldn't access "/sdcard" directly. Your second snippet of code has Environment.getExternalStorageDirectory(). Use that.
You get messages about the SDCARD? Where are they coming from? If you mount it to your local machine, you won't be able to access it from your app while its mounted.

Android-Where does image taken get saved?

Something weird is happening in my application im not sure if it is worth uploading all the code...
Intent pictureIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
pictureIntent.putExtra( MediaStore.EXTRA_OUTPUT, imageUriToSaveCameraImageTo );
startActivityForResult(Intent.createChooser(pictureIntent, strAvatarPrompt), TAKE_AVATAR_CAMERA_REQUEST);
I use this code to take an photo. The photo gets saved in the DCIM folder and also into imageUriSaveCameraImageto which points to sdcard/folder...The image is given the name image1.jpg..once run it works.
Then i delete the files from DCIM and sdcard/folder and run the application again and take a different photo...for some reason the old photo appears in the folder...it must be caching or storing a copy of it else where...does anyone know where and how i can delete it?thanks
Android indeed caches thumbnails of all the photos in another location.
See here:
http://www.droidforums.net/forum/droid-general-discussions/30998-thumbnail-cache-can-cleared.html
I can't give you an exact answer, but my feeling is that the MediaStore is a ContentProvider, so you may be able to call ContentResolver.delete(URI).

Android: getting thumbnails from specific location on sd card

AFAIK accessing thumbnails for images via MediaStore.Images.Thumbnails would generate thumbnails at first attempt, and that's what I need to perform against specific location on sd card.
The question is how to make valid URI to content under specific folder?
All answers I can find use just MediaStore.Images.Thumbnails.EXTERNAL_CONTENT_URI as uri to make managedQuery. And result of it is Cursor that points to all sdcard images, while none examples can be found on how to access only specific folder.
Maybe you could just list files in the directory and parse them to get thumbnails without using content provider. You can use inSampleSize option to get small bitmap not the complete image Strange out of memory issue while loading an image to a Bitmap object.
may be is to late, but for some one will be helpfull
Mihai Fonoage said...
Use something like
File imagesDir = new File(Environment.getExternalStorageDirectory().toString() + "/pathToDirectory");
File[] imageList = imagesDir.listFiles();
for (File imagePath : imageList) {
bitmap = BitmapFactory.decodeStream(imagePath.toURL().openStream());}
Here you have some great tutorial.

Categories

Resources