is there any solution how to choose the saving files location?
maybe with the original file browser, to choose the destination?
thank you!
All you need is Android Directory Picker
Better to save files with your app namespace:
String extStorage = Environment.getExternalStorageState();
path = extStorage+"/Android/data/com.mydomain.myapp/";
It will be deleted when app gets uninstalled.
Here is actually everything about data storing.
http://developer.android.com/guide/topics/data/data-storage.html
From the above link:
If you're using API Level 7 or lower, use
getExternalStorageDirectory(), to open a File representing the
root of the external storage. You should then write your data in the
following directory:
/Android/data/<package_name>/files/
It's probably easiest and expected to save this out to the dedicated area on the external SD card.
You can get this folder by calling
file://localhost/Applications/android-sdk-macosx/docs/reference/android/os/Environment.html#getExternalStoragePublicDirectory(java.lang.String)
File path = Environment.getExternalStoragePublicDirectory(
Environment.DIRECTORY_PICTURES)
You can also append a sub-folder to reference the source better ie. your app.
You can either choose DIRECTORY_PICTURES or DIRECTORY_MOVIES. If it's user created I'd probably stick to pictures.
To be helpful you can also call the media scanner to add it to the appropriate content provider system wide.
sendBroadcast( new Intent(Intent.ACTION_MEDIA_MOUNTED,
Uri.parse("file://" + Environment.getExternalStorageDirectory()))
);
If you MUST get a file chooser going, which isn't the recomened approach to expose the user to the file system. Try the file chooser form Open Intents. http://www.openintents.org/en/node/164
Related
Which way is the best to save file on external storage...
a) new File(Enviroment.getExternalStorageDirectory(), "")
b) new File("/mnt/sdcard/","")
Enviroment.getExternalStorageDirectory() is the best way to save file into external storage.
Take a look at this http://developer.android.com/reference/android/os/Environment.html
Always use
Enviroment.getExternalStorageDirectory().getPath()
instead of hard coding as below...
/mnt/sdcard/
If you choose hard coding way then the system will throw you below message...
Do not hardcode "/sdcard/"; use Environment.getExternalStorageDirectory().getPath() instead
Another problem is that SDCard folder name isn't same for all devices...SDCard name different in Some devices.
In samsung devices, it is named external_sd and in this case, the hard coding way will be failed. That's why following way is the best...
File file = new File(Enviroment.getExternalStorageDirectory().getPath(), "");
Always use
Enviroment.getExternalStorageDirectory() in place of mnt/sdcard/
Enviroment.getExternalStorageDirectory() is the best public API for directly accessing the SD card.
However, you should consider using the new ACTION_CREATE_DOCUMENT intent which allows the user to select a location for saving.
For example, if a device has multiple SD cards, the user can select between them, or they can choose any app participating in the Storage Access Framework.
I want to create a folder in sdcard in an android device and I want to set a folder permission for the creating folder. The folder permission should be that from only from my application this folder should be assessable. No other application should be able to access this folder. Is there any method to create this. Please provide any valid link for this.
sadly it is not possible to create read-only permissions for the sdcard. This is a part of Android's system design and won't be changed soon.
I am making an application in android and I want to make a ready only folder in sdcard.
This is not possible, sorry.
FAT32, the standard SD card file system, does not support file permissions. This means that any file is world readable and world writeable.
String SaveFolder = "/Ready";
String extStorageDirectory = Environment.getExternalStorageDirectory().toString();
File myFolder = new File(extStorageDirectory + Folder);
myFolder.mkdir();
This is a code to make a folder, and just like Tim said: it is not possible to create read-only permissions folder.
As others have said, you can't for the reasons specified.
I'm not exactly sure what you are trying to accomplish, but if you want to create a private file that can't be accessed by other apps, you can create in your app's "data" directory, by doing this,
OutputStream os = context.createFileOutput("myfile.ext", Context.MODE_PRIVATE);
Note that this is not the SD card, it's internal storage, so you aren't going to be able to create a very large file.
I want to create a folder in sdcard in an android device and I want to set a folder permission for the creating folder. The folder permission should be that from only from my application this folder should be assessable. No other application should be able to access this folder. Is there any method to create this. Please provide any valid link for this.
sadly it is not possible to create read-only permissions for the sdcard. This is a part of Android's system design and won't be changed soon.
I am making an application in android and I want to make a ready only folder in sdcard.
This is not possible, sorry.
FAT32, the standard SD card file system, does not support file permissions. This means that any file is world readable and world writeable.
String SaveFolder = "/Ready";
String extStorageDirectory = Environment.getExternalStorageDirectory().toString();
File myFolder = new File(extStorageDirectory + Folder);
myFolder.mkdir();
This is a code to make a folder, and just like Tim said: it is not possible to create read-only permissions folder.
As others have said, you can't for the reasons specified.
I'm not exactly sure what you are trying to accomplish, but if you want to create a private file that can't be accessed by other apps, you can create in your app's "data" directory, by doing this,
OutputStream os = context.createFileOutput("myfile.ext", Context.MODE_PRIVATE);
Note that this is not the SD card, it's internal storage, so you aren't going to be able to create a very large file.
I have a method in my application which retrieves the last saved image in my DCIM/Camera folder and copies it to another location on the SD card. I've just tested it on another phone and found that it defaults saving to DCIM/100MEDIA. How am I able to get this path?
I ended up writing some code which looped through all the folders in the DCIM folder and retrieved the path of the lastModified() folder.
Looks like it is manufacturer dependent. In addition to using methods described in book, it seems also allowing the user to choose/override the default you "discover" would be an important option.
From Pro Android 3: p 579
Unfortunately, there is not a method call to tell you which directory might be used underneath the DCIM directory for Camera
pictures. There are a couple of methods though to tell you where the
top of the SD card is. The first is
Environment.getExternalStorageDirectory() and it returns a File object
for the top-level directory for the SD card.
See the following Google books link for full page text:
http://books.google.com/books?id=RuN0jb4YASwC&pg=PA579&lpg=PA579
other references:
Do all Android phones with a built-in camera use a folder called "DCIM" to store captured images?
http://androidforums.com/android-lounge/5930-definitive-androids-folder-structure.html#post239353
Maybe this can help you:
File picDir;
if (Build.VERSION.SDK_INT > 7)
picDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);
else
picDir = new File(Environment.getExternalStorageDirectory().getAbsolutePath(), "Pictures/");
Hope this can help. Based on this.
How to get FileInputStream for file in internal memory in android which is not inside applications default file directory.
I have created new directory in my application space. So openFileInput("filename") will only work for files in getFilesDir(). And openFileInput("filename") do not accept argument with path separaters "/" so I can change it to ../myfolder/.
Is there any way to get a FileInputStream on this ? ..
Note: Using normal APIs File = new File(... ) gives permission denied errors. And I have already created given Context.MODE_WORLD_WRITEABLE as the permission for my custom folder.
To make it clear :
My file is here ==> /data/data/com.app.package/app_myfolder/file1.tmp
where
"myfolder" ==> is created with Context.MODE_WORLD_WRITEABLE permissions.
I want to open FileInputStream on file1.tmp. (Normally your files are here /data/data/com.app.package/files/file1.tmp and getFilesDir() points to this directory, so also openFileInput("") takes argument which exist in same default directory.)
How to get FileInputStream for file in internal memory in android which is not inside applications default file directory.
You can't, unless the file in question is created using openFileOutput() with MODE_WORLD_READABLE, and that's not a very good idea (since any app can now read that file).
As the file was created by camera activity as a result for startActivityForResult() for MediaStore.ACTION_IMAGE_CAPTURE intent.
The camera activity should be storing the file out on external storage, not internal storage. Use the EXTRA_OUTPUT extra to indicate where the file should go.
So is there any way I can change this permissions ?
Assuming "camera activity" is referring to the one in the Android firmware, you will need to modify the firmware.