Hide image from gallery - android

I need to hide image(not folder) in both file browser and gallery without changing the file location. I tried prefixing the file name with . it hides the image in the file browser but still showing in gallery. Is there any way to hide image from gallery?

Create a .nomedia file in the same (or parent) directory of the image. This will hide all media in the current directory and subdirectories. (The media scanner will not scan this directory).

I need to hide image(not folder) in both file browser and gallery
without changing the file location.
My thought over this problem is
You can change the extension(make file without any extension) so media scanner will not able to detect it.
e.g file name us test.png rename it to only test

Related

Saving to drawable folder programmatically in Android

I'm looking to have a user select an image from the gallery, and have this file saved as a permanent drawable resource when they open the app at a later time. Is this possible?
I mean as an object in the actual drawable folder.
No, it's not possible. "The drawable folder" doesn't exist as a file system folder at runtime - it's part of your (read-only) binary .apk file.
You could instead save the image at internal folder and/or define a preference string.
Check this old answer https://stackoverflow.com/a/3374138/4618976

how to automatically add an image and name it to an xml file in android?

I was wondering suppose you are creating a space in an blank xml file to store attributes such as shirts if you were to upload an image from your sd card, how would you code the event handler for that?

How to set icon for a file?

I am creating different types of Files. For example File extension as.txt, .doc, .xml, .java, .jpg, .png, and etc. How to set the icon to be matched with the files. For example i am creating one pdf file. How to set pdf icon to that pdf file.
You dont have to explicitly set icons for the files, unless you are creating file with your own extension.
The operating system will understand the file type and binds the icon accordingly.
That is why in windows, if you manually change a file's extension, the icon changes automatically. Same case applies to Android also.
If you want to create different files via your android app & want to show the files list along with icon as we can see it in Windows OS, then you have to put all different images of each file extension in drawable folder. example- pdfImage.png, jpgImage.png, pngImage.png etc. Now you have to process the file name to determine the file extension runtime. then update your iconView (an ImageView item) like:
iconView.setImageBitmap(bitmap); // bitmap is the Bitmap image
or
iconView.setBackgroundResource(R.drawable.pdfImage_icon);

Hide folder with photos on sd card

I save pictures to my application on sd card. When I go to gallery I can see that pictures. How I can save pictures which I use in application on sd card but they must be invisible in gallery from phone.
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.
While storing data add these two lines then the content will automatically be hidden and images not visible in device gallary.
File dstFile = new File(file.getParent(), "." + file.getName());
file.renameTo(dstFile);
It works great for me.
You can alternatively put a dot in front of the folder name by renaming
foldername to .foldername
But putting .nomedia file in folder and .foldername usage will hide all media files in a directory
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
My detailed answer can be found here Stop images on sd card from showing up in gallery?

Missing image on html file in android default web browser

I have a html file (contains some text and one image) stored # /sdcard/test folder.
And image is also stored under same folder. I'am able to see the image on html file if i open html file programmatically (using a WebView).
((WebView)findViewById(R.id.webView)).loadUrl("file:///mnt/sdcard/test/report_external.html");
It works. But when i go to that folder and open that html file (using default web browser of android), image file is not getting displayed. It is showing everything except image. What is the problem with default android browser to view the html file? Are there any differences between opening the file using defalut browser & WebView?
Here is my image tag in html
<img src = "file:///mnt/sdcard/test/image.png"></img>
How could i see the image on html if it opened with default browser also?
I think there's something wrong with your img-path. Try to set src="image.png", it should work when both files are in the same directory. Let me know if it works.
Change the name of the image to something else and try. might work.
try file:///sdcard/test/report_external.html
instead of file:///mnt/sdcard/test/report_external.html
That's remove /mnt in your path, does it work now?

Categories

Resources