My app is using images from folder /storage/emulated/0/Android/data/com.android.providers.media/albumthumbs. When I change language and restart phone it is deleting image files from /storage/emulated/0/Android/data/com.android.providers.media/albumthumbs. Now to recreate image file in that folder I have to launch native media player.
I am using Galacy S4 and issue is frequently happens when I change language to Korean.
Do someone know why it is deleting files on langauge change and restart and which action I can use inside my app to recreate image files in /com.android.providers.media/albumthumb like they are using in native media player.
If I delete all images from /com.android.providers.media/albumthumbs how I can fill it again will images of music files on launch of my app. Like if I launch Google Music of Samsung Music Player images are created in the folder. How I can do that on launch of my app.
Maybe too late but I had the same problem in my app.
A workaround which works for me is following
Firstly I load vie media store all album arts. So I can get some file paths but there is no files therefore for begin I check whether file exists
File f = new File(coverPath);
if(!f.exists()){
}
if not then I do this
public void loadAlbumArtById(long id) {
try {
Uri songCover = Uri.parse("content://media/external/audio/albumart");
Uri uriSongCover = ContentUris.withAppendedId(songCover, id);
ContentResolver res = this.context.getContentResolver();
InputStream in = res.openInputStream(uriSongCover);
} catch (Exception ex) {
// do something
}
}
Where Id is album id from media store (MediaStore.Audio.Albums._ID)
After I run this function, art is available again, I don't know why, but it works for me
Related
My application downloads a set of images and stores them in the internal storage by creating a folder.
The problem is the images are being shown in the gallery. This should not happen, is there a way to programatically hide the images but still be usable by the app?
Thanks in advance.
EDIT:
This is only happening to the android version of the app. In the iOS it is not showing in the Camera Roll.
This depends where you download the images: If you download them on your Pictures folder or inside of a public folder from sdcard/internal memory then MediaScanner scan them so your pictures will be visible in the Gallery app.
To avoid this you can try one of the following solutions:
Add a .nomedia file inside your destination folder
OR
Download your pictures in app cache directory by using LocalFileSystem.TEMPORARY.
Something like
window.requestFileSystem(LocalFileSystem.TEMPORARY, 0, function(fs) {
fs.root.getDirectory("media", {create: true}, function(fileDirectoryEntry) {
// var destFile = fileDirectory + "/" + filename;
// downloadPicture(srcUrl, destFile);
});
});
The downside of this solution is that when the app is removed, your pictures are deleted as well.
I have an app which performs processing on an image selected by the user using from the gallery, after processing the modified image is then saved back to the original image's folder with a modified filename. On specific devices (mainly Samsungs) the new KitKat permission limitations severely limit where a non system app can write to e.g. external SD card or back to typical gallery locations.
The documentation advises to write to the private package specific folder obtained via
getExternalFilesDir(null)
This is fine and the image is saved correctly but then a subsequent call to
MediaScannerConnection.scanFile
fails to update the central media database correctly as the modified image doesn't appear in the gallery, even a reboot of the device which should force a full scan of all media doesn't trigger the image to be displayed.
In other words the following code doesn't work:
File appDir = MyActivity.this.getExternalFilesDir(null);
File file = new File(appDir, "new_image.jpeg");
// Process image and write file away...
MediaScannerConnection.scanFile(this, new String[] { file.getAbsolutePath() }, null, new MediaScannerConnection.OnScanCompletedListener() {
#Override
public void onScanCompleted(String path, Uri uri) {
Log.i(LOG_TAG, String.format("Scanned file: %s", path));
}
});
The onScanCompleted method fires but the gallery doesn't show the new image.
Has anyone seen this behaviour, does MediaScanner not scan 'private' app folders and if so how else do I get the gallery to detect and display the new image.
If you want images to be picked up by the gallery, you should put them in the proper public location. You can get the proper location using Environment.getExternalStoragePublicDirectory().
Here is my code:
File storageFile = new File("/mnt/extSdCard/DCIM/Camera/IMG_123456789.jpg");
if(storageFile.exists()) {
//copy the file to another folder
MyCopyFoo(storageFile);
if(storageFile.delete()) {
Log.d("Debug", "Success!");//have shown
//refresh sth
}
}
After operation, I checked the system gallery, and there is still a thumbnail in it.
When I restarted the system, it was gone.
I know there is some other way to handle this- the "setting"=>clear sth
What if I wanna deal with it in the code above?
Use MediaScannerConnection to notify the system of modified media files and to regenerate their metadata and thumbnails.
Mediascanner runs as part of the boot sequence so that's why a reboot also fixes the issue.
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.
I'm having an issue with opening internal data files in native applications
Its properly important to point out that I'm fairly new to Android development but not new to programming
Setup
I have a mobile Air application which i am running on an Android device. To load PDF's/ play videos within the application I have written a native extension to load the files via their native application.
Problem
When testing the app i found that file's stored in the external storage were loading fine and files in the internal storage were presenting messages from the native applications like cannot play file or cannot open file.( files in internal storage are downloaded and saved on the Air application end ).
This lead me to think its the permission setup within Android.
I know that files within the internal storage are private by default
I have read how to write to a file setting its permission using openFileOutput
but as the file already exists this won't work. I could load the file in and spit it out again but this isn't ideal as will result in what might be unnecessary overhead.
I'm not sure how to proceed, do i need to set a manifest properties on the Air App side? Android App side? both sides? If so which one and where
Or is their a way to change it at run-time, i found the setReadable function but its at API level 9 and i am idealy aiming a little lower than that.
Any help is greatly appreciated
public static void openFile( Activity parentActivity, String filePath, String fileType, String mimeType ) {
//Create the file we are to create
File fileToOpen = new File(filePath);
//Check if the file exists
if( fileToOpen.exists() ) {
//The path of the file we want to open
Uri path = Uri.fromFile(fileToOpen);
//Create a new intent of the file we want to view
Intent intent = new Intent(Intent.ACTION_VIEW);
//Set the path and the mime type for the file
intent.setDataAndType(path, mimeType);
//Remove any other activities
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
//Check that its within the try and catch block
try {
//Open the file by stating a new activity
parentActivity.startActivity(intent);
}
catch (ActivityNotFoundException e) {
//Make a pop-up informing that we don't have an application to open the file
Toast.makeText( parentActivity,"No Application Available to View " + fileType,Toast.LENGTH_SHORT).show();
}
} else {
//Display an alert which will show that the file dosn't exist
Toast.makeText( parentActivity, fileType+" file dosn't exist", Toast.LENGTH_SHORT).show();
}
}