LibGDX: I have game-data files created at runtime for debugging purposes (a replay system). The files are stored in Gdx.files.local() whether on desktop or android. Now I want to copy the ones that were created on android so I can debug them on desktop.
Running Gdx.files.getLocalStoragePath() on android returns /data/user/0/com.[my domain].[my app]/files/. Using Windows Explorer I do not see my app's folder in /data/user/0, or anything else for that matter. So private storage indeed it is, but how nonetheless can I get hold of these files, without root if possible?
The solution may be manual copy or in code, whatever works. Just to note, the file names are unknown without seeing the files first. They were named using current date-time. The extension is known, though.
EDIT
I discovered Android Studio's Device File Explorer. I connected my device, tried to see inside my app folder and app data folder, both showing 'Operation not permitted'.
So to put the question in simpler words, is rooting the phone really the only way for developers to see the files created by their apps?
Or is there a magical gate somewhere known only to select few zen masters who guard the secret through the generations? Because I sure ain't finding it.
I'm not sure that there is a way to write changes in the system file without having root access but you can read them. According to this Blog, You can access those files and put it in your desktop. You can download RAR app from googleplay.
Related
Here the problem: my app will generate some files, and I want to give to the users the opportunity to exchange these files between them.
This requires 3 steps:
Saving the data: easily done in Storage implementing the
functions required by the Externalizable class;
Sharing the data: done (probably, right now it's impossible to check if the
result is correct because the missing step 3) with the sharing
methods offered by the framework, as soon as I understood I needed
to use as mimetype "application/octect-stream";
importing the downloaded data (shared by another user): this one I can't manage to
find a way to make it work. Loading the files from the app's Storage
is easy, but accessing to the folders out of the app's Storage is
something I can't manage to do.
I used FileSystemStorage in the hope of gaining access at least to the Download folder that (mostly) every phone has, but apparently I can't manage to accomplish the task
Using the FileSystemStorage on Android, for example, I have access to
/storage/emulated/0
/storage/emulated/legacy
file:///system
The first two being related to the Storage of the app.
Acceding to file:/// I obtain a long list of folders, a partial list including
media
logs
sdcard
Removable
...
root
...
But when I try to access some of these, they all appear to be empty. Either I make some mistake or the app can't see their content.
So I wonder if there is a way to accomplish the task, namely to have access to the files (probably in the Download folder) the user has downloaded, to import them.
Phone apps live in isolation within the phone. Android literally creates a separate Linux user for every app so they don't step on each other and damage the phone. iOS does similar tricks.
As a result apps can't just write a file to downloads and can't just list all the files there. This would violate the users privacy. So the native API to share a file is usually separate from the files API. We do have a share API in the CN class which lets you share images etc. to an arbitrary OS app. See isNativeShareSupported and share.
Ok, maybe I found a solution for reading the files from the Download folder in an extension of CodenameOne called FileChooser.
According to this blog post it should give access to, between the others, the Download folder (at least in Android).
I'm going to try it and, when everything is ready and tested, edit this reply to say how it worked out for me.
I've been searching for hours and came across a lot of non-sense about read-only this and that and folders and directories and viewing the phone fs, etc. etc.
All I want to do is write to a file that is on my PC for an Android project. I've tried to use local paths (Windows) and have been met with read-only fs system problems, even after completely converting the desired folder to read AND write, Android refuses to get it. I set uses-permissions in my manifest with WRITE_EXTERNAL_STORAGE and WRITE_INTERNAL_STORAGE, but no luck.
I've tried to write to the phone, via emulator and actual physical phone, but every search I make turns up nothing (searching for the name of the file).
How can I write to a log file, any file that is where my development source code is? I need to digest JSON data from a web service call and I need it to be written to a local file so that I can work with it. The calls are through Android, currently an emulator, and an install on a physical device, yet no log is written because either a read-only problem which is non-sense, or I just can't find the damn file.
Any help would be greatly appreciated.
I guess ultimately the question I asked was just too messy. I wanted to know where I could find "local" logs on my Android device, which I can open and read myself in some text editor. I also wanted to know where "local" logs/files are written to my hard disk when testing the app via emulator.
At this point, I haven't found anything relating to a log file or any arbitrary file being able to be written from an Android app to a local dev PC without being pulled from something like adb.
I have found the solution to where I can write arbitrary files to an emulator or phone's filesystem (Source: https://www.journaldev.com/9383/android-internal-storage-example-tutorial):
FileOutputStream fos = Main.getAppContext().openFileOutput( "myfile.txt", Context.MODE_PRIVATE );
fos.write( "Hello, world".getBytes() );
fos.close();
Some things to note (Android SDK 26+ at least, others are untested):
FileOutputStream works very well.
"Main" refers to whichever entry point class you're using for your app. It most likely (or must?) extends AppCompatActivity.
Context.MODE_PRIVATE seems to be required.
AndroidManifest.xml permissions READ_EXTERNAL_STORAGE, WRITE_EXTERNAL_STORAGE, READ_INTERNAL_STORAGE, WRITE_INTERNAL_STORAGE do NOT seem to be required.
Important: Files will be saved to /data/data/YOUR.APP.PACKAGE/files/.
This was also helpful: https://developer.android.com/training/data-storage
I am having problem i have just created a simple android app.I want to know that the folder of package name i.e. com.xx.xx in Android/data as usually created when we install an app is not present on my device how to solve this problem.
Is something that i am missing in manifest i have declared only permission for write external storage and everything in manifest file is same as default.
From what I have seen the folder com.xx.xx in Android/data for the normal cases which you see only gets created if you exclusively write files to the external storage using something like getExternalFilesDir() or getExternalCacheDir() method. So unless you are writing it to the external storage you might be creating them as files stored privately by the application.
If you are looking for these files stored privately by the application, i don't think these are shown by the default file browser in an unrooted device. But in an emulator or device connected to android studio, you can use "Device File Explorer".
If you don't see its tab, go to: View --> Tool Windows --> Device File Explorer.
In the Device File Explorer, Select your device then expand: data --> data --> com.xx.xx
And within it you should be able to see the privately generated files.
Also for us to understand what you are actually using, there is no way unless you add the code of how you are writing these files you mentioned.
I need to load "configuration" type files for my program in Android, they are both .bin files containing dictionary data for the NLP library. I'm a bit new to Android still, and I'm having trouble finding a folder to place the files in so I can access them when the activity starts.
I also need to create/save/load a filetype specific to my program, and I don't know where to put it either. All I've been able to find on here is people using the getAssetManager() function to fetch input streams, but I explicitly need File objects for me to be able to load them into my pre-existing desktop software code I'd like to reuse (plus the libraries require them anyway)
I've also seen people using a "res/raw" folder, however the ADT did not generate this "raw" file when I made the project - so I'm not sure what to do there either.
Here is how I usually start the software in the desktop version, but I need to fetch these files in an Android environment:
brain.start(new File("memboric.core"), new File("en_pos_maxent.bin"), new File("en_sent.bin"));
core = brain.getInterpreter().getCore();
The memboric.core file can be generated, but I need to know WHERE and HOW to do so.
Thank you very much for your time, feel free to direct me to other resources if you feel this question is inadequate.
TLDR; how do I load "static" files for the software to function (needs to be included with software), and how to create/load/save "personal" files into an appropriate area of the device?
Use Context.getFilesDir(). Your application can read and write files in that folder and they'll automatically get deleted if your application gets uninstalled.
From that point forward, you can create, delete and read from files like any other Java application.
the "raw"-folder you can create it on your own. So check this out, which shows how to handle files in Android: http://developer.android.com/training/basics/data-storage/files.html
We have to make a Java application demo available on Internet using JWS. It goes pretty well; all that's missing is making working directory files available for the application.
We know about the getResource() way... The problem is that we have different plugins for the same application and each one require different files (and often different versions of the same files) in their working directory to work properly. So we just change the working directory when we want the application to have a different behavior.
Currently, the demo is packaged in a signed jar file and it loads correctly until it requires a file from the working directory. Obviously, the Internet users of this demo don't have the files ready. We need a way to make these files available to the WebStart application (read/write access) in its working directory.
We've thought of some things, like having the application download the files itself when it starts, or package them in the jar and extract them on startup.
Looking for advices and/or new ideas. I'll continue working on this... I'll update if I ever find something reliable.
Thank you very much!
I said I would share what I found in my research for something that would fit my needs. Here's what I have so far.
I have found that the concept of current working directory (CWD) does not really make sense in the context of a Java Web Start (JWS) application. This had for effect that I stopped trying to find the CWD of a JWS and started looking for other options.
I have found that (no, I didn't know that) you can refer (using getResource()) to a file in the root directory of a JAR file by simply adding a '/' in front of its name. ("/log4j.properties", for example.) The impact of this is that I can now take any file which is only referred to in a read-only manner in the root of that JAR file (which is really only a ZIP file). You can refer to any file in the root of the JAR file using AnyClass.class.getResourceAsStream. That rules out the problem with read-only files required to run the application, at the cost of a switch in the code telling whether the application is run from a valid CWD or from a JWS context. (You can very simply set a property in the JNLP file of the JWS application and check if that property is set or not to know where to look for the file.)
For write-only files (log files in my case), I used the property , adding a directory with the name of the application: <user.home>/.appname and added log files to it.
Read/write files (which I don't have in my case) would probably simply go at the same place than write-only files. The software could deal with uploading them somewhere if needed, once modified, I guess.
That's the way I deal with the problem for now.
Note there is a service you can explicitly ask for, to get file access to the computer (unless you go all the way and ask for full access (which requires signed jar files)).
Then you need to determine where these files need to go - basically you have no idea what is where and whether you may actually write anywhere. You can create tmp-files but those go away.
Would a file system abstraction talking to the JNLP-server do so you store the users data on the server?