Good day! In fact, I want to save files from the server to a folder in which they will not be visible to anyone other than this application, I just worked only with the assets folder.

Tell me how to register it in the method:

File myIcon = new File(getExternalFilesDir(null) + File.separator + "myIcon.png"); 

it turns out that I need to register my path instead of getExternalFilesDir (), but I do not know which path the assets have

  • one
    You cannot save the file to the /assets folder. use internal storage - tim_taller

2 answers 2

It is impossible to save something in assets at runtime. all its contents are packaged in an apk file at compile time. Those. The assets folder is used only to store any files that are not suitable for placement in resources but are needed at the time of the first launch.

You will have to write files somewhere else, in assets will not work.

  • All resources in the application are read-only (not for writing or editing), in short :) - pavlofff
  • @pavlofff, yes, but you can actually twist the other apk with your application and correct the contents of the agro-industrial complex if you have a root, which, in general, allows you to write the file to the assets ... But, of course, I think the vehicle does not really want this) - YuriySPb

In order to organize the work of only your application with files saved from the server in a local folder, you need to organize the storage of these files in the internal memory of the Android device. When saving files in the internal memory of the device, access to them will be organized only for your application (if the phone is not rooted). Those. the file will get access rights that only your application has. When saving the file in external media, any application can technically access the file. When saving a file to internal memory, you can get its directory as a File by calling the getFilesDir () method. To create a file, you can use the File () constructor, which passes a File element, for example:

 File file = new File(context.getFilesDir(), filename);