I want to save file on phone. new File(directory, myCustomFolder).
My files are large and MP3
1 - Environment.getExternalStorageDirectory() is not always access to save file. On some phones that don't have sd card not available and return nothing. :(
2 - getFilesDir() after unistall my app my files remove. (Is not the right place to store files) :(
3 - getCacheDir() after unistall my app my files remove. (Is not the right place to store files) :(
4 - getDataDirectory() after unistall my app my files remove. (Is not the right place to store files) :(
Now, How do I distinguish the right place and secure and always available to save my files?
I need a SD card if there was not, I have my files stored on internal memory and the public(Public means no save to data app folder). ?!!
Apps like WhatsApp and Telegram how to make folder into two external memory and internal memory?
Please help me.Thanks
You can always create a folder for your app in the Downloads folder. It will always be there. You can access it via Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS). And since you are saving files, it makes it even a more appropriate place to store it, don't you think so?
Environment.getExternalStorageDirectory() GOOD WORKING.
solution is: android API 23+ need check dangerous permission:
https://developer.android.com/training/permissions/requesting.html
Related
My application downloads files from the server and save them somewhere. Where should I put the folder to save the files? Not in assets right? Should I create a folder somewhere parallel to "bin"/"libs"/"res" folder?
Another question: should I put the downloaded files in internal storage or external storage?
Actually you can not save the downloaded file in either of this folders because they are not allowed to make modification at run time.
Best option goes according to your requirement, as if you file is too large and you are not much worried about it's security then you can store them on SDCARD(External storage). and if your file is small enough and much secure then you should save them on internal storage.
Check most popular application store their files on SDCARD but encrypted way...
Hope this ans your question
Store your downloaded files in a folder on an external storage directory. like
String yourFolderPath = Environment.getExternalStorageDirectory() + /com.yourapp/;
Store files in that folder.
if its just few files, it would be safer and more convenient to use the context.getCacheDir(). with it, you can be sure that it will always be there unlike sdcard which can be locked when the phone is in storage mode. it doesnt require manifest permission. You don't even have to worry about security unless your user is rooted.
IDE Eclipse
Using emulators
I am downloading files from a webservice. I have no problem saving the files to the sdcard. This can then be accessed via a filemanager.
However, if there is no sdcard available I would like to save the files to 'Downloads' on internal storage. I can't seem to get the files to download to 'Downloads' as it would were you downloading from a browser.
I can however manage to save the files in the application directory on internal storage. Eg data/data/com.example.appname/files/.
The problem is this can only be access via the application.
I need the files to be available to the user to view/open after downloaded.
Is this possible? Or will the user have to have an SDCARD?
This also depends on the device + provider, some are locked so people cannot access their internal storage at all.
So if you want to cater to people without SD card, save in application directory. They cannot access if they don't have root-access. Nothing you can do about this.
This is quite normal behavior.
Best practice is warn users of their options: saving on SD card or internal storage. And mention consequences if you want.
the find the downloads folder use:
http://developer.android.com/reference/android/os/Environment.html#getExternalStoragePublicDirectory(java.lang.String)
File downloadFolder = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS);
but just like others mention, if the SD-Card is not there, there's not much you can do about it, just give a warning to the user.
On the link I posted there's good examples on how to check the existence of the directory and availability of it.
Can anyone help me ? Is it possible to create shared preference files in sdcard rather than on private path of an android application.
You cannot modify where shared preferences are stored.Its a private storage. if you want to use sd card use
Environment.getExternalStorageDirectory(). and get the path of directories stored in sdcard.
it is possible by reading&writing the xml file into the external storage ,but it's not the same as sharedPreferences. you will have to implement your own way , or use the android code of this class.
however , there are some disadvantage over using the internal storage:
anything you store on the sdcard is visible to every application and the end user can read it by just opening it.
only in the internal storage you get some sort of protection against reading the file , so that only rooted devices can read the files.
external storage can also be unmounted , so the data can sometimes be unreachable. you need to handle possible errors that can occur because of this.
uninstalling the app while the sd card is mounted means that the data will stay on the sdcard .
I want to develop an application which lets user protect their files / folders . It is very much the same as existing apps where user can select the files to be hidden and those files can be accessed only from my app which is password protected.
I got enough resources about the encryption algorithm.
Here my doubt is :
where should i keep my encrypted files. It should be within my app folder. But this folder if i create on phones internal storage, will that not lead to memory restrictions. My app let user to add images / videos or any other file to protection. If i keep the folder on the sd card, the questions are it will restrict app to be run on only mobiles with sd card . Also the content of sd card can be accessed by others ( i am right here ? )
The next doubt is that i see most of those apps i see if i remove protection it is restored in its previous folder. How is it achieved . Is it like keep mapping table an duse that to restore ?
Please help me with answers for my questions. Thanks a lot for your time and help
According to my investigations of the same problem, there is no built-in encrypted storage in Android system. Hence, I'd recommend you following approach:
Encrypt file content with any algorithm. See here(1), here(2) and here(3).
Use MODE_PRIVATE when creating file with, for example, openFileOutput(String, int)
I am creating android application which contains DB that needs to be hidden(not able to access by the user)in the SD Card. Can anyone tell me how to do this?
Any file stored on the SD card is accessible both by applications running on the phone, and by users who have mounted the SD card (both while it's in the phone and otherwise).
You can change the file properties to make it 'hidden', but it will still be easily found. There is no way to make a file on a public partition like an SD Card 'secure' in the manner you describe - users will always be able to copy, delete, and potentially change the file.
The best solution to your problem is to look into ways to encrypt your database to record it securely. You won't be able to prevent users from deleting or copying the file, but you should be able to make it difficult for them to read data from it or modify its contents.
For an easy solution, just prefix the db file with a . (like .dbfile). This will hide the file on Linux based systems, including android.
I am assuming that you want to hide the file to prevent users from accidentally deleting/changing it.
SD cards cannot be secured in the fashion you seek.
just name the file start by ."Dot"... ".myFolder/.myfile"
You can create a folder whose name starts with a dot(.) example (.dbfiles) android See these folders as configuration folder and do not show content of these folder in applications like gallery,music player...You can see these folders with advance file explorer like Es File explorer
Sdcard you cant't! Internal app data partition is the place for you.