Android - .nomedia not working for images - android

I have images, which are read from sdcard only by particular application so I want to hide it from image gallery. I have put .nomedia file in it, but this file is ignored, images are still showing in Gallery. I have put it with "." in the beginning. Still not working. Any ideas?

I'm guessing you're using Android 4.0, as .nomedia functioned properly until then. The AOSP bug report for the issue explains:
MediaScanner on Android 4.0 fails to forget already-indexed files when it encounters a .nomedia file, but it does honor it if it's present on the first pass. So the workaround is to simply rename the directory. Of course you can change the name back after the next scan, if you like.
Update: I suppose the complete solution would be to actually force a media scan after renaming the directory. I haven't tried it, but something like this should do the trick:
sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED, Uri.parse("file://" +
Environment.getExternalStorageDirectory())));

Well... I admit I'm only guessing, but since it got a +1 in the comment, I'll give it a whirl as an answer. Since this is your own app, change the image file's extension to something totally unique ".myimagefile" for instance, and see if that hides it from Android. Meanwhile you know what files to load into your own app, and how to save them.

The .nomedia bug is right and you CAN add it to a preexisting image folder.
You can force the gallery to re-index after you created the .nomedia file by renaming the folder, run gallery (the "hidden folder should now be missing), and rename the folder back to what you want. It should remain hidden.
I just did it again to ensure it works on my phone. Android 4.0.4.

Here's something I found myself:
http://www.transformerforums.com/forum/asus-transformer-faq/17765-solved-nomedia-doesnt-work-under-honeycomb-ics.html
However, a little alteration to that method:
Download and install SDRescan app
Clear data for Gallery app
Clear data for Media Storage app
Open SDRescan app downloaded from step 1
SDCard should be re-scanned and all directories containing .nomedia files should be ignored at this point.

In my memory card I have thousands of photos that overwhelm the media-scanner. Then in the root folder on my memory card, renamed from "RootFolder" to ".RootFolder"
Became the hidden directory and not use more .nomedia
Try this.

The .nomedia file is preventive, not curative (in Android 4.0), and it is a bug.
If you had a .nomedia file and images are already in it, Gallery will still search for images.
You need to create your .nomedia file before puting images in it.
Edit: all folders starting with a dot are not scanned (because hidden).

With Media Storage 4.1.1 on my Samsung Galaxy Note 2, none of the tricks given above works fully, in this sense: directories containing .nomedia files are still scanned, which can drain the battery a lot (though the result is ignored in the gallery), and also directories with names starting with a '.' are still scanned :-(
I resorted to using the "Media Scanner Root" app, which allows to disable the crappy media scanner altogether. This is apparently achieved by something like pm disable com.android.providers.media/com.android.providers.media.MediaScannerReceiver
BTW, disabling/freezing the Media Storage app itself has the bad effect that the selection and binding of ringtones and notifications does not work any more (what a wonderful design), but when only disabling its scanner component, one can still use, e.g., the ES File Explorer for selecting tones.

Gallery is not updated so often and some thumbnails are still on the view. For this u need to reboot the phone or programmatically update gallery, by following code.
/**
* This method is must to reflect changes on gallery, if some file is
* deleted or moved, <b> no updation is shown on gallery till phone is
* rebooted </b> or <i>till this method UpdateGallery(Activity activity) is
* called</i> UpdateGallery
*/
public static void UpdateGallery(Activity activity) {
activity.sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED, Uri
.parse("file://" + Environment.getExternalStorageDirectory())));
}

You might consider using the APK Expansion Zip Library (requires API level 5 or above) to read files that you will have installed to the SD card as part of a Zip archive. A description of this library can be found here:
http://developer.android.com/guide/market/expansion-files.html#ZipLib
Presumably, files stored in a ZIP archive on your SD card will not be displayed by the Gallery.
In addition, if you have images that your app reads from (but does not write to) the SD card, and that should only be available to your own app, and that could be delivered when your app is installed or updated, then it might make sense to take advantage of a new Google Play facility to incorporate them as part of your app when it is installed.
I'm guessing that you are storing your images to the SD card because they are too large to fit into your APK file (given its 50MB size limit, which is even smaller than that in practice for certain devices, due to buffering issues).
If so, then you might consider that Google Play, as of 3/5/2012, supports the attachment (to your app) of up to two "expansion files" of up to 2 Gigabytes each. The APK still has a 50MB maximum, but the expansion files raise the total storage available to over 4 GB. Those expansion files are served for you by Google, and they are maintained in a specific SD card folder that is specific to your app, and can be accessed using an API provided by the Downloader Library (requires API level 5 or above).
Here is Google's announcement of this change:
http://android-developers.blogspot.in/2012/03/android-apps-break-50mb-barrier.html
And here is a detailed description of the facility:
http://developer.android.com/guide/market/expansion-files.html
Note that while this facility is new, the libraries have been supplied with the Android SDK for use with earlier API levels. For example, on my installation, I find the API-8 versions here:
<Android SDK base folder>\extras\google\play_apk_expansion\
That same folder includes the abovementioned APK expansion Zip library in its zip_file sub-folder.
I have not personally used this facility yet myself, and so am describing this based solely on the cited references.

Related

How do I write to the SD card on Nougat/Android 7.0 (VR friendly)?

I'm looking for a way to make my VR Android app (for Samsung Galaxy S7 and S9) able to write files to the SD card (e.g. by downloading a .zip file and unzipping it there).
The app is mostly going to be used by people, who don't know a lot about Android/smartphones and don't want to have to deal with anything complicated (not necessarily seniors but close enough), that's why I want to make it as easy as possible for them, which also includes making choices myself (and setting it up for them) instead of showing complicated dialogs.
Special requirements:
The files must not be deleted when the app is uninstalled - that's why I can's use getExternalFilesDirs() (Storage Volume).
The folder everything happens in has to be easily accessable, so the zip files can be transfered to the SD card on your PC too (instead of downloading them through the app in case they are too big) without having to go down a huge amount of levels and remembering a long folder path.
Using Storage Access Framework isn't a good alternative either because not only is picking folders nothing that's especially VR friendly but it also requires knowledge about folders most of the users simply won't have and/or won't want to deal with every time they open my app. But: If there was a way to only show this once (on the very first start after installing the app) and maybe even set the root folder to the folder I chose, so the users only have to hit "accept", that would be worth a try (unless there's an easier way).
Yes, I did set the android.permission.WRITE_EXTERNAL_STORAGE permission and also enabled the "force allow apps on external storage" developer setting but trying to write to the SD card still throws an "Access Denied" exception.
Are there any others ways to write to the SD card that are VR friendly?

Android app consisting of Sound Effects - how to copy files?

I wanted to create an app that consists mostly of sound effects - imagine a theme of sound effects.
The UI of the app would reflect the general theme and consist of buttons like "Copy sounds to device" and "Delete copied sounds from device"
Once the app has copied the sounds to the device, I would like to make the MediaScanner aware of the new files.
Problem: With the limits on the SDcard, how is it possible for a non-system app to copy the files to the sdcard or even delete them ?
Whilst working on this feature, I discovered :
1)getExternalStorageDirectory() is useless on new versions of Android
2) the Media Scanner is unable to access the folder supplied by getExternalFilesDir()
Solution
Copy files to a public folder obtained with getExternalStoragePublicDirectory()
https://developer.android.com/reference/android/os/Environment.html#getExternalStoragePublicDirectory(java.lang.String)

How to secure downloaded images Android

I have to do some stuff. I'm downloading images using web-service, after successful download of each image, I'm using "AES" encryption algorithm to encrypt that images. I'have done encryption successfully. But whenever I'm going to open Gallery of device, I am able to seen that downloaded images encrypted by me. I don't want that. I wanna secure that images that can prevent access from Gallery.
I understood the whole process here.When I am storing each image after download Gallery capture that image and store into its cache so before my encryption process may be Gallery populate that images.
-> My Encryption process : Download Image - > Store into SDCARD - > Encrypting Image - > Delete the real Image
But this is not deleting from Gallery also.
So in short I wanna secure that images that can prevent access from Gallery. Let me know your best suggestion about my process is right or wrong? May I have to do a few changes on it? or have you nice idea instead of my process ?
Thanks for your best suggestions.
You must add an empty file to your images folder called .nomedia. This will prevent the MediaScanner from indexes images in that folder.
However, there is a bug on ICS that makes this slightly harder. On ICS, your folder must have the .nomedia present before you add images to it, or else the images will be indexed.
Another, slightly less compliant option is to begin your folder name with a dot (something like .foldername). As Android is UNIX based, this will make it a hidden folder, and hence not have the MediaScanner scan it.
I have got a proper solution. That will also work with higher versions.
You can keep it private with your application's private folder using following directory :
String mDirectory = getPackageManager().getPackageInfo("com.example.myapp", 0).applicationInfo.dataDir;
You can store your private data into this package. It will prevent access as well as prevent indexing from Gallery. So you don't need to worry about it's encryption process also :) . May be this folder will not provide much space. But atleast it will be help us.
Sounds like below solution might work for all versions -
(Storing videos, images and audio files that can not be accesses by others)
For this you have to store your data in External Storage with creating a folder name starting with the .(dot) then this folder is hidden from the FileExplorer.In this folder you need to create a .nomedia file and place your Images and video then images and videos are can not be visible to User in the Gallery.nomedia folder files can not be read by the gallery.

Stop images on sd card from showing up in gallery?

I keep some png files on the user's sd card. Some users report that these images are showing up in their gallery application. Sounds like the gallery implementation on some devices search out any image files they can find on the sd card and show it in the gallery. Is there a way to tell the system not to include these images in the gallery? It's just an annoyance to the users.
Thanks
You can hide individual files from the gallery with a . prefix. For example .myimage.png
I'm not sure what version dependencies the above has and it doesn`t work with some third-party picture tools like the Gallery.
You should add a file named .nomedia into the directory where your images are. You may need to eject and re-insert the SD card before the images disappear from gallery (or otherwise trigger the media scanner) after creating this file on a phone that the Gallery has already picked up the files in the Gallery.
I think the .nomedia option is the best solution, although again, third party tools may not respect the .nomedia flag.
Hiding your files from the Media
Scanner Include an empty file named
.nomedia in your external files
directory (note the dot prefix in the
filename). This will prevent Android's
media scanner from reading your media
files and including them in apps like
Gallery or Music.
In http://developer.android.com/guide/topics/data/data-storage.html#filesExternal
You may also consider saving those files as cache files or in the internal memory. More info in that link.
just keep the files in a folder and name the folder starting with a '.'
for example:
Pictures
Videos
.private--> will not be scanned for any media
Eboks
Along with these solutions using picasa is an alternative too... and .nomedia or .foldername suggestions are generally useful but...
Including accepted answer none of the solutions solve album covers problem.
A large number of android users are storing album covers inside the album folder and .dirname or .nomedia solutions are hiding all from both gallery and music player. The required functionality is hiding from gallery and showing in music player (else there is no reason for not deleting cover pics if we will not see them right? )
Here is the solution ;
Rename all album cover picture files to albumart.jpg
(or what picture you desire to hide from gallery)
This way gallery will not include them and music player will still use :)
Alternatively for any folder if you place a folder.jpg file in it that file will be ignored by gallery application.
As you can see we can only exclude max 2 files (pictures) from gallery application, not more :(
After you do this changes no need to clean caches of gallery and media scanner and reboot (still an option) just run an application that triggers scanning of media on every run. I prefer vaulty it refreshes media gallery on every run on photos, but there are lots of apps, maybe you already have one installed , just use it no need to install an application for just this media scan deal.
Knowledge source : http://code.google.com/p/android/issues/detail?id=35879
While making external directory use something like this
File mediaStorageDir = new File(Environment.getExternalStoragePublicDirectory("YourDirectoryName"),"YourFolderName");
Instead of
File mediaStorageDir = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES), "YourFolderName");
These files won't be detected by gallery for more reference check saving media files on this link
http://developer.android.com/guide/topics/media/camera.html#intent-receive
Neither Windows nor Android allow the creation of the file .nomedia
It's seen as a file extension without a name.
i tried everything but only this solution worked 100% you need to plug in your urb and format the sdcard check quick format box and press on restore defaults and then it will show everything in ur gallery just you need to move all your images again :)
You can easily create the folder in Windows using Powershell
New-Item -path 'C:\Users\Google Drive\Pictures\.nomedia' -itemtype directory

Sharing different media types from my own directories on Android

I'm downloading files of various types (pictures, audio, videos) through my application. The folders mentioned in the Android Documentation under "Saving files that should be shared" don't exist, neither on the SD-cards of my actual device nor on those of my emulators.
However, creating them wouldn't hurt, but in this case I'd like to keep everything together within my applications folder, for example
/mnt/sdcard/MYAPP/Pictures.
But if I do that my pictures won't appear in the Media Gallery.
Is there any way to explicitly request Android to include the content of a specific directory into the Media Scanner?
Thanks alot
S.
Okay, it took quite a while. But now it appears. Thanks anyways... :)

Categories

Resources