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.
Related
I am using cordova file plugin to delete image from gallery. here is the code
window.resolveLocalFileSystemURL(path+filename, function (result) {
result.remove(function(data){
console.log(data)
});
});
As per above code I am getting success return and file is also deleted from folder. But When I am going to the gallery it is showing me a blank thumbnail. When I am trying to open this file it is showing only grey color. In details it is showing the old path. But in that path file does not exists. I think this is a kind of cache. How can I delete that blank file?
My code was ok, all I need to use Media Scanner to scan the gallery.
In my application I want a image gallery that will show the images that were taken from the Android camera. So, I am trying to copy files from the Android storage to the assets folder to make a image gallery.
For that I have write the following code.
string sourceDriectory="";
string targetDriectory="";
void Start()
{
CopySomething( sourceDriectory, targetDriectory);
}
static void CopySomething(string sourceDriectory, string targetDriectory)
{
UnityEditor.FileUtil.CopyFileOrDirectory(sourceDriectory, targetDriectory);
}
In this code I am not getting how can I will set the sourceDriectory path and the targetDriectory path.
You don't need to copy images only to show them in your app. You can just directly access the image files and display in your app.
Take a look at here for how you can access images from gallery.
One part of my current project is downloading images from URL then saving to SDCard. But the problem is all of saved images in sdcard is displayed in android gallery page. What I want is "I don't want all of my saved images in android gallery."
Add ".nomedia" file. Did not work? Try the second option.
Save your files to a folder that starts with ".", e.g., /sdcard/.myimages/
You can create .nomedia file using this code:
String NOMEDIA=".nomedia";
File Folder = new File(Environment.getExternalStorageDirectory() + "/mydir");
if(Folder.mkdir()) {
nomediaFile = new File(Environment.getExternalStorageDirectory() + "/mydir/"+ NOMEDIA);
if(!nomediaFile.exists()){
nomediaFile.createNewFile();
}
}
I found a simple way(I think so).
Create a folder in 'Android' folder(where data & obb folders are present) and put your media(pics,videos, etc.,) in the folder you've created.
Gallery app ignores that 'Android' folder. Simple :-)
its so late and i know other answers are complete but i think putting .nomedia file makes all pictures in that particular folder hidden :
just change extension of image file programmatically and this way gallery cant detect it as an image . eg if your image is "pic1.jpg" rename it to "pic1.aaa";
and when you want show it again rename it again
I have created a Worklight application and added to it the Android environment. This application has a button to take a photo using the device camera, and an img tag in the HTML which displays the captured photo.
I followed this PhoneGap Camera API.
Now I am trying to store that image into the SD Card but fail doing so. my
EDIT: I changed my code as below:
function takeimage() {
// Retrieve image file location from specified source
navigator.camera.getPicture(getImageURI, function(message) {
alert('Image Capture Failed');
}, {
quality : 40,
destinationType : Camera.DestinationType.FILE_URI
});
}
function getImageURI(imageURI) {
var gotFileEntry = function(fileEntry) {
var img=document.getElementById("thisImage");
img.style.visiblity="visible";
img.style.display="block";
img.src=imageURI;
alert("got image file entry: " + fileEntry.fullPath);
var gotFileSystem = function(fileSystem){
// copy the file
fileEntry.moveTo(fileSystem.root, "pic.jpg", null, null);
};
// get file system to copy or move image file to
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, gotFileSystem, fsFail);
};
//resolve file system for image
window.resolveLocalFileSystemURI(imageURI, gotFileEntry, fsFail);
}
//file system fail
function fsFail(error) {
alert("failed with error code: " + error.code);
}
Everything working fine(capturing image and image available in app cache folder) except moveTo method.
fileEntry.moveTo(fileSystem.root, "pic.jpg", null, null);
I put fileSystem.root in alert and I am getting Object object. So the folder location is not available to move that image(And I think its the real problem).
This, in fact, has got nothing to do with Worklight.
Since you are already using Apache Cordova to access the device's camera to snap a photo, you should also use it to store the image file to the device's SD Card.
Here are a couple of SO questions to point you to the right solution for you:
How to move captured image in PhoneGap to a folder in sdcard
Capturing and storing a picture taken with the Camera into a local database / PhoneGap / Cordova / iOS
Note #1: your link to the PhoneGap Camera API points to v1.0.
Worklight 5.0.6.x uses PhoneGap 2.3.0, so be sure to use the correct API version.
Note #2: make sure you have added permission to write to the SD Card by adding the below line to the android.manifest file:
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
Note #3: in case #2 above is not enough, try getting the SD Card location like this:
File sdDir = Environment.getExternalStorageDirectory();
use this option in your takePicture callback
{
saveToPhotoAlbum: true
};
Also use all other option too as per your requirement. This will save your image to photolibrary.
saveToPhotoAlbum: Save the image to the photo album on the device after capture. (Boolean)
It will save your image to sd card without writing any extra code.
I have an application which has loads of pictures. The total picture is saved in an SD card due to large number of picture. The main problem is that the pictures are available in gallery. I want a way to hide the picture from the gallery but must be available for my application.
I did put " . " in front of the file name to make it hidden
but the images were not displayed in may application also!
Anyone.. help.. please
thanks..
Gallery handles all media files it knows about, so if you want it to stay away of your assets you got two solutions. First, add .nomedia file to the folder with your images, and Gallery should skip it (most image viewers would honor .nomedia, yet there's no guarantee). Other solution is to use some own, proprietary file format, so Gallery or other tools won't be able to process it. I'd recomment .nomedia if that's sufficient solution.
Add .nomedia file into the image folder. The important thing is that, the folder should be empty, when you add .nomedia file. If the folder contains some images before adding '.nomedia' file, the gallery will not hide those images, and it will hide the images added after '.nomedia' file. So The first file added to the image folder should be '.nomedia'.
Hope dis will help you
Thankx,
This line of code can add the .nomedia file in your directory and makes your images hidden from the gallery
String NOMEDIA=" .nomedia";
File Folder = new File(Environment.getExternalStorageDirectory() + "/mydir");
if(Folder.mkdir()) {
nomediaFile = new File(Environment.getExternalStorageDirectory() + "/mydir/"+ NOMEDIA);
if(!nomediaFile.exists()){
nomediaFile.createNewFile();
}
}
i think the place where you save the images matter, try to save them into application cache directory, or files directory.
you can get access to cache directory using : getCacheDir() in your activity.
and your files directory: getFilesDir()
these two directories must not be visible or accessible to any other applications expect your application,
I used assets to accomplish this in my app.