New to Android, working on an app for Vuzix M300s. The app needs to access a file that contains the IP address and port of a web server. I believe I will need to manually place a pre-configured file on the M300s using adb shell, but I cannot figure out where on the device to place it so that the app can find it. Via Android Studio 3.1.3, I have placed a file in the assets folder which I can open & read, but using adb shell I cannot locate it. (I get permission denied for a lot of actions like ls). How do I get a file on there? Or is there a better way?
Asked
Active
Viewed 2,388 times
2 Answers
2
Note that the assets
folder in your project only exists on your development machine. The contents of this folder are packaged into the APK file when you build your app. In order to read any of these files, you need to use Context.getAssets()
as explained in read file from assets.

Code-Apprentice
- 81,660
- 23
- 145
- 268
-
Thanks for the info about assets. I suspected as much and I assume it's the same for raw. So where can I drop a predefined file that the app can open? – Allan Jul 18 '18 at 19:40
-
@Allan `raw` is similar, in that it is not a directory on the device. Accessing raw assets uses different function calls, though. Either of these can be used to provide a static file that is deployed with your app and should fit your purposes. – Code-Apprentice Jul 18 '18 at 21:21
-
@Allan Another option is hosting it on a server and your app makes a HTTP request for it after installation. – Code-Apprentice Jul 18 '18 at 21:26
-
The thing is, each installation will be unique, contacting a web server/port unique to that company. I don't want to make a different APK for each install. – Allan Jul 19 '18 at 03:24
0
Figured it out.
To move/copy a file to the M300s for an application
- move the file to the device (in the sdcard folder)
- .\adb push C:\temp\file.cfg /sdcard/
- move the file from /sdcard/ to the desired location
- a) go into the shell
- '> .\adb shell
- b) change to the application's permissions
- $ run-as com.foobar.appname
- c) copy the file into the app's 'files' folder
- $ cp /sdcard/file.cfg files/
- a) go into the shell
Within my app, I was able to read this with
FileInputStream fin = openFileInput("file.cfg");
InputStreamReader rdr = new InputStreamReader(fin);
char[] inputBuffer = new char[100];
int charsRead = rdr.read(inputBuffer);
String fileContents = new String(inputBuffer);
rdr.close();
Log.i(method, "charsRead: " + charsRead);
Log.i(method, "fileContents: " + fileContents);

Allan
- 23
- 7