My application downloads jpgs from a website using DownloadManager and store them in the /sdcard/Android/name.app/ directory to be used in several Fragments in the application. The download works great however, the jpgs are visible in the Gallery application, which I don't want since they are just assets for my application. I cannot figure out how to have them not show up in the Gallery application. I even tried adding .nomedia files to the directories are they are created. Any help would be appreciated!
DownloadManager myDownloadManager = (DownloadManager) myActivity.getSystemService(Context.DOWNLOAD_SERVICE);
Request myRequest = new Request(Uri.parse(episodeArtLink));
myRequest.setNotificationVisibility(Request.VISIBILITY_HIDDEN);
myRequest.setVisibleInDownloadsUi(false);
myRequest.setDestinationInExternalFilesDir(myActivity, Environment.DIRECTORY_DOWNLOADS, myFilename);
myDownloadManager.enqueue(myRequest);
The issues seem to be caused because MediaScanner is adding the Images to the system database even though I have not asked it to.
I have created a test app that demonstrates the problem. If you click the Download button the Google logo will show up in the app. If you go into the Gallery app you should also see the Google logo in a gallery named Download. If you go to Settings -> Apps and Clear the Data for Gallery and Media Storage then the Google logo will be gone and won't show up again in Gallery because the file is under /sdcard/Android/data/ which is protected by the .nomedia file. You can go to /sdcard/Android/data/com.example.downloadmanagertest/files/Download/ to verify that the images are still on the phone. Even after a reboot the images don't show up in Gallery if you clear the Data for Gallery and Media Storage. I have tested this on both a Nexus 4 and a Nexus 7 running 4.2.2.
Source: https://dl.dropboxusercontent.com/u/114414/DownloadManagerTest.zip