Downloading files from webservice to specific location on android device - android

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.

Related

How to copy internal directory audio files to external directory in Android 11

I have a music app which lets user purchase music, and used to store it in own folder in external storage(works perfect till android 10).
From android 11, initially I used getFilesDir(internal storage) and the version has been live on play store, now user isn't able to see the physical file in file manager, I am aware about how scoped storage work, if my files would have been in external directory, user would be able to see it in ASD(app specific directory) but now in internal storage that also isn't accessible.
All downloaded files are visible to me in emulator at path: /data/user/0/com.packagename/files/FolderName/Music/
But I need it to be accessible by user so that he can access it.
Also, Is there anyone founded a way to transfer(move,copy) our files to Shared Directory(Downloads/Music), I am aware it needs MANAGE_PERMISSION which wasn't allowed by Google.
Really appreciate any help.
I don't think now you have option to backup your data, most probably your users are going to sue you.
No magical solution for this. I think #blackapps is just bluffing.

What storage method 2 use 4 saving and deleting .txt files programmatically on specific external storage, and loading .txt files on android 11?

I looked up scoped storage but that won't work because of the permission request seeing my apps feature has to delete files on backpress (if user changes folder name)/ onstop, and also multiple .txt files need to be loaded when user restores/backsup notes.
Media store doesnt say anything about .txt files nor about deleting them, that i could find. And it cant be public storage(documents or downloads) because it also writes to folder name that user types. Any help would be great, currently app is rejected from using manage_external_storage. It seems like manage external storage is the only way to go.
Thanks
this is my current code
FileUtil.writeFile(FileUtil.getExternalStorageDir().
concat("/Folder/text.txt"), e2.getText().toString());
FileUtil.deleteFile(FileUtil.getExternalStorageDir().
concat("/Folder/text.txt"));

Saving file under /Download gives name /storage/emulated/0/Download. Sometimes the file is not accessable

On my Samsung devices I put a file in the /Download folder. When I select the file within my app (via a file browser), the file is called /storage/emulated/0/Download/myfile.db. This name is stored in my app settings.
At the start of the app the file should be opened. First the app checks if the file exists. In some cases, say once every 2 weeks, the file is said to be not existing! This happens also at my friends mobile since half a year.
Why is that happening? For years everything ran smoothly.
This code runs for 6 years. Of course I added the permissions stuff.
Your help is much appreciated!
You can't use the Download as an guaranteed storage place for your files. You should use the Internal storage for the app. This is what Google has written about the download folder:
This space is called external because it's not guaranteed to be accessible—it is a storage space that users can mount to a computer as an external storage device, and it might even be physically removable.
Here you can read more about the Internal storage and the External storage in Android.
Here is some more information about the Download folder from Google.
Caution: The external storage might become unavailable if the user removes the SD card or connects the device to a computer. And the files are still visible to the user and other apps that have the READ_EXTERNAL_STORAGE permission. So if your app's functionality depends on these files or you need to completely restrict access, you should instead write your files to the internal storage.

Where do you put downloaded filed in android

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.

Security of files in android

We are trying to create an app which will download eBook from server and store it locally on sdcard. We tried to DRM eBooks, after we download an eBook the DRM will take care of the security of the eBook. But later due to some reasons we left the DRM concept. Now I want to know whether we can store the eBook securely in the sdcard. The user cannot do any operations in the file other than viewing. Can we store the file in some other location where the user cannot view the file at all. In iOS we can download the file inside the Bundle itself, but for android???. We tried storing the pdf as a BLOB file in DB and tried to read it from there, in that case also we need to write the file and then read it. I am really confused on this Issue, can someone suggest me a good approach on how to proceed further. Any help would be really appreciable.
Personally I've avoid the SDcard given it's pretty much open to all apps, as #commonsWare mentions having it internal storage offers the Android app sandbox security.
Have you considered IOCipher from the excellent guys at the guardian project it's build on SQLCipher and it allow you to create a encrypted virtual disk. The part I love about it is that it's a clone of the java.io libraries so you should only have minimal code changes.
Files stored on the external storage are easy to read by other applications or from user's PC. You might need to encrypt your files if you don't want anybody else to get access. Well encrypted files can be places anywhere in the system without any risks of being read.
Storing files on the internal storage in your case does not sound good, because there are still too many devices out there with the limited amount of internal storage, where every megabyte counts.
Can we store the file in some other location where the user cannot view the file at all.
Not on external storage. You can put the book on internal storage, in which case only rooted device users would have access to it outside of your app.
i) keep the files encrypted which are important to you.
ii) decrypt the files and move to the internal storage during runtime.
iii) Access your files only from internal storage.
Following these things will keep your file and method calling safe as they are accessible only to internal storage.
Example:(access moved assets files from internal storage )
file:///android_asset/ => file:///data/data/com.test.exmple/files/"
You can also try tools like quixxi that do this for you transparently.

Categories

Resources