Reputation: 23
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?
Upvotes: 1
Views: 3296
Reputation: 23
Figured it out.
To move/copy a file to the M300s for an application
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);
Upvotes: 0
Reputation: 83527
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.
Upvotes: 2