0

I need to read html and text files to be properly formatted and displayed, but I don't want to be using a physical smartphone to do this because the amount of detailed changes makes the task cumbersome and lengthy.

I'd rather copy those files to a directory on my PC that Android Studio can read, write and check on Android Emulator's Device File Explorer. How can I do this? Thanks!

  • Possible duplicate of [read file from assets](https://stackoverflow.com/questions/9544737/read-file-from-assets) – Juan Feb 24 '19 at 14:51
  • Thanks Juan, but I think I left something out: WHERE on my PC's hard disk should I place those files? Or... how can I map AS's virtual file system to my PC real file system? – PepinhoDoSamba Feb 24 '19 at 15:01
  • To make the files availabe to the android emulator you have to add them to the assets folder of the project. The folder doesn't exist by default, you need to create it at the same level of res folder. (Tip in Android studio using File new there is an option to create the assets folder) – Juan Feb 24 '19 at 15:03
  • File -> new -> Folder -> Assets Folder – Juan Feb 24 '19 at 15:08
  • Ok, it's done as you said. But... 1) If I "invalidate and restart" the IDE the directory shows up under "resources" (weird), next to "drawable", "layout" and the rest of resources -good so far. 2) After a few seconds "resources" becomes "res" and my directory ("grammartips") disappears from the list. 3) The directory remains physically alive on the hard disk and under "res". Any other good tip? – PepinhoDoSamba Feb 24 '19 at 15:25
  • Mover the folder one up. It should be at the same level as res – Juan Feb 24 '19 at 17:39
  • Juan, I finally got the solution. Thanks again! – PepinhoDoSamba Feb 24 '19 at 18:10
  • Now, I've got a new question. I'd rather use a virtual phone to develop and use my physical phone to ensure I'm doing the right thing. I've found that "context.getAssets().list('grammartips');" gets me the directory where my text files are stored (that is "src/main/grammartips") on the virtual phone but "File(tipPath).listFiles()" gets me the same files on the physical phone. I can't seem to find a way to reach those files with one common set of methods, i.e. how can I get the "assets" directory on my physical phone? – PepinhoDoSamba Feb 27 '19 at 00:09

0 Answers0