where does exactly getFilesDir() method address? - java

I have some files you can say a trained model that I need to get their path in my activity class.
I want to use getFilesDir()but it return "data/user/0/com.example.abc/files/".
I just don't know which folder or directory I have to paste my files exactly in order to be in this path so that these file can be get through getFilesDir().

This is the folder on your device
You can find it by opening "Device File Explorer" (this is a collapsed tab in the bottom right of your Android Studio - written vertically on the right edge, bottom)
There you open the folders data/data/com.yourpackage.name/files
Upload your files to this folder and your app can pick them up.
Hope this helps.
Use this way only to test things. For a production scenario you need to package your files in the project, like in the raw or assets folders of your app's resources, so they are contained in the .apk or .aab app bundle.
You can not access this folder via Windows Explorer. The Device must be in developer mode and adb must be running, so you can only access it through android studio or adb command shell. Keep that in mind.

Related

What is the right way (resp. folder) to save files under Android 11 (API30)?

My Android-APP creates text files that have to be read by other apps.
I originally chose the following directory, which no longer works:
Environment.getExternalStoragePublicDirectory((Environment.DIRECTORY_DOCUMENTS))
Right now I'm trying the directory:
getFilesDir()
The problem here is that no other app can access this folder.
I'm puzzled as I simply don't know which directory I can use for an exchange between apps.

Extraction APK : what are .png# files?

I would like to extract the images from an android game.
Firstly, I took the APK on my windows 10 laptop then I extracted the files (rename files.apk to files.apk.zip and extracted it with 7zip).
Inside my folders I got many .png files but I get an error when I try to open one. Each .png file has another file with the same name but with .png#. Some even have 2 otherfiles with them : one with .skel (can't open this one too) and .atlas (I can open it with notepad):
Did I make mistakes? What can I do to "repair" all these png files?
Thank you for you help!
If you are authorised to do so then you can apktool.
Its easy to use and may that #png files will be converted to some meaningful resource.
Installation for Apktool
Windows:
Download Windows wrapper script (Right click, Save Link As apktool.bat)
Download apktool-2 (find newest here)
Rename downloaded jar to apktool.jar
Move both files (apktool.jar & apktool.bat) to your Windows directory (Usually C://Windows)
If you do not have access to C://Windows, you may place the two files anywhere then add that directory to your Environment Variables System PATH variable.
Try running apktool via command prompt
Link

External storage folders of Android 4.4.2 device do not appear in windows 10 browser

I would like that the users of my Android application be able to copy data files to their computer via USB. They should additionaly be able to erase the files on the android device once copied. To this end, my application creates .csv files which are stored in the external storage space, as recommended by Google. I have created the destination folder thanks to this method:
static File getMyStorageDir() {
File file = newFile(Environment.getExternalStoragePublicDirectory(
Environment.DIRECTORY_DOCUMENTS), "MyDir");
if (!file.mkdirs()) {
Log.e( "LogFile", "Directory not created");
}
return file;
}
On the Android device I can browse the .csv files in "/sdcard/Documents/MyDir". When I connect the device to a Win 10 computer in MTP mode, the "Documents" folder does not appear. If I try to create the "Documents" folder in the Windows explorer, it will fail, (probably) proving that the folder exists, but is hidden. On the other hand I can create a folder "foo" in Windows and put files into it. The "foo" folder and its content will appear in the browser (ES File Explorer) on the device after a while. To finish, I can erase files in the "DCIM/Camera" folder...
I think I am close but I am missing something...
The MTP cache gets out of date until a reboot of the phone.
A workaround is:
Clear the "Media Storage" app's data and restart the device

Making folders of images available in the project

I need set of images in jpg format to be in this specific folder.
path = getFilesDir() + "/imagefiles/";
After root my mobile phone, I manage to find the specific folder. The location is /data/data/*packagename/files/imagesfile/*png images.
I can copy the image manually into the folder but i want to deploy a project that already has the image in it.
I have tried several solution but none really works for me. Please help me.
I can copy the image manually into the folder but i want to deploy a project that already has the image in it
It is not possible for you to create an app that automatically has files in getFilesDir() immediately upon installation.
What is possible is for you to put images there on the first run of your app. Those images could be:
downloaded from the Internet
packaged in assets/ in the project, then copied into your desired location using AssetManager and open()
packaged as raw resources in the project, then copied into your desired location using Resources and openRawResource()
etc.

Where to find the created file in Android emulator in Windows

I created a simple file write/read app in Eclipse and have successfully tested that it could read what it wrote. The structure is fairly simple. I use FileOutputStream to write a samplefile.txt using openFileOutput and a FileInputStream using openFileInput to read it back. The only minor thing is that I don't know where is the file on my physical hard drive? Can anybody point me to where I could find the file in Windows?
If you dont give a absolute path the file will be creataed in aplication directory.
This is /data/data/packge-name-of-your-app/
e.g:
/data/data/com.example.test/
See more http://developer.android.com/training/basics/data-storage/files.html
Go to DDMS perspective, select the emulator which you are using, go to package explorer tag ,then you will get a list of folders hierarchy.
Go to /data/data/
Now you will see a list of packages installed, search for the package name of your app and expand it.
Here you will see the files which your application created when it was running.
P.S : You cannot find this file on the physical drive of your computer,because it is present in the storage of the emulated android virtual device. This storage cannot be directly accessed by you.

Categories