Copy file to assets folder - java

After searching 1 hour i do not found any solution to my problem.
I want to move a file from sdcard to assets folder and also overwrite the existing file in assets folder (both file are sqlite database have same name with just a little difference in data )
??

Actually, The behaviour of the android .apk file is read only so the directory structure which are in that apk file follows the same, So no one can write this files or make changes on that at runtime,that's why You can't make a changes in /asset folder at runtime. you can read file from it (means copy files which are available in asset to any internal storage or /sdcard but not write it to vice-versa)
Its apply on all the directories which are build in .apk files. As per docs.

Assets folder are not Writable it is only readable so you cant copy from sdcard to assets, yes you can copy from assets to sdcard

If you want other apps not to access your database then what you can do is
Download the database from website. create a temp database also in app directory.
getDatabasePath() this will give you the path of the dummy database you have created now replace this with the one you downloaded.
PS.: User and apps having root access still able to access it and you cant do anything in that scenario

Related

How can i make android application load its assets from external storage folder rather than its local assets folder builtin in apk?

Is there any way to load application assets from external storage ("DCIM") folder rather than its ("apk") builtin ("assets") folder. Please tell me how to do it?
I have given read write permissions too and I have tried giving path by
String pathToAssetFolder = "file://"+Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM) + "/assets/";
Please let me know how can i load these assets contents from external directory?

Writing to text file created manually inside app

Is it possible in Android, to manually add a file inside a project and then, modify it? Example:
"I have a test.txt file in the following path: "app/src/data". I would like to make a method to write a given String in the test.txt file."
Is that possible? I been looking everywhere, but can't seen to do such an easy task.
If you mean modifying files inside the APK itself then it's not possible. Besides, the folder structure you see in the project is not the final structure on the APK (just unzip your APK, it's a .ZIP really): Fpr example, the source directory is all compiled into a classes.dex. The res/ directory is compiled and fully copied ...
Take a look at How to write files to assets folder or raw folder in android?
and https://developer.android.com/training/basics/data-storage/files.html
You can read raw files stored in /res/raw, or assets stored in assets/ , but you cannot modify stuff inside the APK itself.
What you can do is create and modify as many files as you wish from the different places Android gives to any app, such as:
CACHE directory (context.getCacheDir() -> /sdcard/Android/data/your.package/cache
External files (context.getExternalFilesDir() -> /sdcard/Android/data/your.package/files
Arbitrary directories in the SDCARD.

Create a new folder and insert files in that folder. Google Drive

I want to create a hidden folder in user's Google drive root directory and then want to insert some text files in that folder and later want to retrieve that files. I tried the quick guide and files are uploading fine but in the root directory and files are visible to user. From here I know how to create an empty folder. . But from here I do not understand how to use that code to insert the file in a particular folder.
So my Question is how to create hidden folder and perform CURD operations on files using drive API.
You're looking for the appdata folder. See here:
https://developers.google.com/drive/appdata

Delete database file from assets folder

I want to delete a file in assets folder in run-time. I have a database file in assets folder that copies to data folder at run-time but after installing my app the size of app become twice as large (assets + data folder)!
How I can delete database file from assets folder to avoid this?
You can't delete a file at runtime that was delivered with your App.
See this discussion about it:
How to remove a file in assets at run time?
The whole content of your APK is read only and can not be modified
in addition to the above answer, one thing you can do is preferExternalStorage in manifest..which will help

how to download folder containing files(pdf,png etc) from php server in android

i want to download folder containing files like pdf,jpg,png etc from web services.I have written a application that can download pdf,png file.But i want to download folder containing several files. So my question is- is it possible to download folder and if yes then how can i download folder from server in android. thank you
If you can download one file, why wouldn't you be able to download several? Create the folder on Android, queue the files and start the next download when the current is finished, filling the folder. Also Android supports ZIP, so that might be your best call.
Folder is nothing but an FILE but a different type of file. Once you get the folder you can list down the files in it. You already have URL with the folder, u just need to append the URL of the folder to the files in it and download them one by one.

Categories