I am not able to find a text file on my local Windows computer to open it in Kotlin - Android Studio. I tried placing the file in an assets folder and I tried various path variations but nothing so far. Some code examples use either the application.open command or something that requires Context. I don't know what to import to enable those commands. Any help would be appreciated.
Asked
Active
Viewed 545 times
0
-
How do you intend for the text content to get to the Android device? Is your intention to package it with the app? – CommonsWare Mar 18 '21 at 20:53
-
Good question. I would like the file to be in an assets folder within the app. However, I am open to any solution at this point. – David Campbell Mar 19 '21 at 20:07
-
"I would like the file to be in an assets folder within the app" -- then do that. Use `AssetManager` and its `open()` function to get an `InputStream` on the asset. You get an `AssetManager` by calling `getAssets()` on any `Context`. See [this](https://gitlab.com/commonsguy/cw-jetpack-kotlin/-/blob/v2.0/DiceLight/src/main/java/com/commonsware/jetpack/diceware/PassphraseRepository.kt) and [this](https://gitlab.com/commonsguy/cw-jetpack-kotlin/-/blob/v2.0/PdfProvider/src/main/java/com/commonsware/jetpack/pdfprovider/MainMotor.kt). – CommonsWare Mar 19 '21 at 21:06
-
https://gist.github.com/r0b0t3d/492f375ec6267a033c23b4ab8ab11e6a // for file path doc – Akash kumar Jul 22 '22 at 05:38