My android app (created by air) saves the token shots at /DCMI/ address but it dosent show them in gallery albums.
How can I find androids photo album directory address so I can save the pictures in them and enable them to be shown in the photo galley
this is my code :
var directory:String;
if (rad1.selected){
directory = "mnt/sdcard/DCIM/SHEKAR/";
}
else {
directory = "/DCIM/Camera/";
}
var savePath:String = directory;
i need replace cameraroll directory to "/DCIM/Camera/" tanx .
Try this:
http://developer.android.com/reference/android/os/Environment.html#DIRECTORY_DCIM
Also, make sure that there's no .nomedia file in your directory or one of the parents.
Related
I'm using react-native-document-picker in order to pick files and send them to the server. After picking the file, I use RNFetchBlob.fs.stat(uri) from rn-fetch-blob package to get the real path from the URI that the picker gives me. It works fine with internal storage files but when I choose an image from "SD card" section the stat function throws an exception which says something like this:
failed to stat path null for it doesn't exist or it's not a folder
Surprisingly, when I choose "Images" section and go to the SD card folder and choose the very same image it works just fine!!
I have the same problem with "Downloads" section, too.
The URI that the picker returns is this when I choose the image from "Images" section:
content://com.android.providers.media.documents/document/image%3A76431
and when I choose from "SD card" section:
content://com.android.externalstorage.documents/document/F673-1818%3Abbb.png
Right now I'm using this code but it's not the right solution because it's somehow dirty and it doesn't work on all devices.
if(uri.substr(0,57) === "content://com.android.externalstorage.documents/document/"){
let filePath = decodeURIComponent(uri.substr(57));
let subUri = filePath.replace(/:\s*/g, "/");
filePath = "/storage/" + subUri;
return `file://${filePath}`
}
Is there a nicer way to get the real path of a file in SD card from it's URI?
I appreciate any idea.
OS: Android
My requirement is to open all images and video's of specific folder.
I have refereed this link, Now I am able to show a image in gallery but I want to show all images from a specific folder. Almost all link I have tried on stack but did not get success.
You can set path in File object initialize at that time.
File folder = new File("/sdcard/Photo/"); in this tutorial default path is /sdcard/photo/ at this place you can set your path then get your files.
I sinc it is not good idea but you may write your own searcher in all files on mobile phone for example
public ArrayList<File> getAllphotos(String path){
ArrayList<File> photoPath = new ArrayList<>();
File yourDir = new File(path);
for (File f : yourDir.listFiles()) {
String mas[] = f.toString().split("\\.");
if(mas[mas.length - 1].equalsIgnoreCase("png") || mas[mas.length - 1].equalsIgnoreCase("jpeg")){//or other formats
//it is picture
photoPath.add(f);
}
}
return photoPath;
}
call this wis iternal and external storage
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've written a small file sharing program in android where user can select multiple files for sharing via my app, either from native Android gallery or some file manager (like ES File Explorer). To start with, I'm just displaying the selected file paths in a TextView of MainActivity. Here is my code snippet:
if (Intent.ACTION_SEND_MULTIPLE.equals(getIntent().getAction())
&& getIntent().hasExtra(Intent.EXTRA_STREAM)) {
ArrayList<Parcelable> list = getIntent()
.getParcelableArrayListExtra(Intent.EXTRA_STREAM);
for (Parcelable parcel : list) {
Uri uri = (Uri) parcel;
String sourcepath = getPath(uri);
filepathNameArray.add(sourcepath); //building file path name array from gallery
myTextView.append(sourcepath + "\n"); //displaying selected files' path in textView
}
}
The above code works fine when user selects multiple files from Gallery, but the app crashes when I select files (for sharing via my app) from ES File Explorer. Can anyone please suggest a workaround for this? Thanks for your help!
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