I need to copy files to the system partition of the emulator. As it is read only by default, I use the command "adb remount" to have write permissions and I can then copy the files.
My problem is that when I close the emulator and that I restart it, the copied files were missing. It's very annoying because I must write file permissions that are read at startup of the emulator (platform.xml file in /system/etc/permissions)
You may need to add those files to the firmware that was used to create the emulator image.
The system partition you saw is only a tmp file which will be created during each execution is the reason why you will lose all your files.
The emulator will copy the system.img to the tmp file (something like /tmp/emulator-dDiaPX). All your modifications are made there. So it is easy to understand why all your files are gone, since they have never appeared in the real system.img.
In order to see the opened files, You can use:
lsof -p pid-of-emulator
The right method to do so is to place your files at the directory /data/ or /sdcard/.
Related
I am developing an application using ionic framework.
The app creates files (*.json) and stores them in /data/user/0/ when i verify whether they exist or not, the result was true which means the files exist in the mentioned directory and I can access and modify their content without problem, but when I check the directory with a file manager or from the computer, no result, the directory is empty.
Could someone tell me what should I do?
use adb to copy the file. Even if it's in root dir, u should have access to it via adb.
Do adb pull data/user/0/filename.json path_on_ur_comp.json.
this will copy the file to the directory you define in the 2nd parameter.
// EDIT:
adb is part of the Android SDK, stands for Android Debug Bridge.
You can use this for MANY MANY different reason but of course, the "main" reason is to debug Android devices. You can use it to transfer files in your case.
In Windows, it's located here:
C:\Users\USERNAME\AppData\Local\Android\sdk\platform-tools\adb
In Mac, it's lcoated here:
/Users/USERNAME/Library/Android/sdk/platform-tools/adb
Depending on which OS you use, open that either with Terminal (Mac) or Command Prompt (Windows).
Once you do that, run the following command:
For Mac:
adb pull data/user/0/filename.json /Users/USERNAME/Desktop/somefile.json
For Windows:
adb pull data/user/0/filename.json c:\Users\USERNAME\Desktop\somefile.json
This will copy the file and put it on your desktop
Is there any way to dynamically view the application specific cache in Android? I'm saving images to the cache (/data/data/my_app_package/cache) and I'm 99% sure they're saving there, but not sure how long they're staying around.
When I look in the cache using the DDMS File Explorer within Eclipse, it's always empty. I've also tried examining the appropriate cache dir in ADB and again it's always empty.
Any suggestions?
You may use this command for listing the files for your own debuggable apk:
adb shell run-as com.corp.appName ls /data/data/com.corp.appName/cache
And this script for pulling from cache:
#!/bin/sh
adb shell "run-as com.corp.appName cat '/data/data/com.corp.appNamepp/$1' > '/sdcard/$1'"
adb pull "/sdcard/$1"
adb shell "rm '/sdcard/$1'"
Then you can pull a file from cache like this:
./pull.sh cache/someCachedData.txt
Root is not required.
On Android Studio you can use Device File Explorer to view /data/data/your_app_package/cache.
Click View > Tool Windows > Device File Explorer or click the Device File Explorer button in the tool window bar to open the Device File Explorer.
Documentation
Unless ADB is running as root (as it would on an emulator) you cannot generally view anything under /data unless an application which owns it has made it world readable. Further, you cannot browse the directory structure - you can only list files once you get to a directory where you have access, by explicitly entering its path.
Broadly speaking you have five options:
Do the investigation within the owning app
Mark the files in question as public, and use something (adb shell or adb pull) where you can enter a full path name, instead of trying to browse the tree
Have the owning app copy the entire directory to the SD card
Use an emulator or rooted device where adb (and thus the ddms browser's access) can run as root (or use a root file explorer or a rooted device)
use adb and the run-as tool with a debuggable apk to get a command line shell running as the app's user id. For those familiar with the unix command line, this can be the most effective (though the toolbox sh on android is limited, and uses its tiny vocabulary of error messages in misleading ways)
You can check the application-specific data in your emulator as follows,
Run adb shell in cmd
Go to /data/data/ and navigate into your application
There you can find the cache data and databases specific to your application
Question: Where is application-specific cache located on Android?
Answer: /data/data
Cached files are indeed stored in /data/data/my_app_package/cache
Make sure to store the files using the following method:
String cacheDir = context.getCacheDir();
File imageFile = new File(cacheDir, "image1.jpg");
FileOutputStream out = new FileOutputStream(imageFile);
out.write(imagebuffer, 0, imagebufferlength);
where imagebuffer[] contains image data in byte format and imagebufferlength is the length of the content to be written to the FileOutputStream.
Now, you may look at DDMS File Explorer or do an "adb shell" and cd to /data/data/my_app_package/cache and do an "ls". You will find the image files you have stored through code in this directory.
Moreover, from Android documentation:
If you'd like to cache some data, rather than store it persistently, you should use getCacheDir() to open a File that represents the internal directory where your application should save temporary cache files.
When the device is low on internal storage space, Android may delete these cache files to recover space. However, you should not rely on the system to clean up these files for you. You should always maintain the cache files yourself and stay within a reasonable limit of space consumed, such as 1MB. When the user uninstalls your application, these files are removed.
Here is the code: replace package_name by your specific package name.
Intent i = new Intent(android.provider.Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
i.addCategory(Intent.CATEGORY_DEFAULT);
i.setData(Uri.parse("package:package_name"));
startActivity(i);
I am making one app on Android and I have no idea what is doing one file which is installed after app installation. This file is quite big (this is about this same size as installed apk - even after uninstall ~ 5MB) so this is the reason of my question.
he file is set in data/local/tmp/'name of my apk'.apk
What is it and when it is deleted, because when I'm testing my app on emulator and uninstall it then it still exists.
EDIT AND ANSWERS:
I am not sure of my app is using tmp files. The only file or resource my app is using is movie placed in resources folder which is around 5MB. Deleting this file after app uninstall brings back free space. Before uninstall no. But I want to have deleted it melodramatically or not created at all because this file makes me app 2 times bigger.
The files in there are temporary files and you can safely delete them.
For instance, these are created when you:
Install an APK trought the command line with adb install (the temporary file will have the same name as the original file);
Install / Run an application through Android Studio (the temporary file will have the application package name).
To easily list all the temporary files, you can use the following command:
adb shell ls /data/local/tmp
To remove all of them, you can just use the following command:
adb shell rm /data/local/tmp/*
The .apk is your application. You'd be Sad if Android deleted it behind your back :)
http://developer.android.com/guide/developing/building/index.html#detailed-build
http://www.ibm.com/developerworks/xml/library/x-androidstorage/index.html
This file is the uploaded apk on emulator. Like normal file upload on device.
I have an xml file being written by an app that is set to MODE_PRIVATE, but I now want to read that file outside of the phone, for debugging purposes. In Eclipse, I can access other files made by the app and copy them to my computer, but I can't even see this private file. Merely changing the file to MODE_WORLD_READABLE file doesn't seem to help. I think the file is being stored on an internal "SD card" that can not be removed from the phone, but there are also two other folders in the File Explorer that are either empty or inaccessible: asec and secure.
Does anyone know how the file can be accessed?
If your app is installed in debug mode, you can get your private files on a device without rooting.
Go to [android-sdk]/platform-tools folder and run adb shell.
run-as com.example.yourapp
cp -r /data/data/com.example.yourapp /sdcard/
(Where com.example.yourapp is the package name of your application.)
After executing the steps above, the private folder of your application is copied into the root of your sdcard storage, under your package name, where you have permission to download and view them.
Note 1: If you don't need to download them, then instead of step 3, you can use unix commands to navigate around and list files and folders.
Note 2: Starting from Android Studio 2.0, you'll find more files in the cache and files/instant-run folder, related to the Instant Run and the GPU Debugger features, placed there by the IDE.
You will need to connect the phone and do some magic to let your sdk work with it (I think put it in debugging mode?). Go to where you unzipped the android sdk:
C:\android-sdk_r10-windows\android-sdk-windows\platform-tools>adb shell
#cd data/data/com.yourpackage.yourapp/files
#ls
You should see your file listed. You may need to run "ls data/data" if you're not sure what the fully-qualified name of your app is. From here if the file is small and you just want to see what's inside it you can run:
#cat yourfilename.xml
Alternatively:
#exit
C:\android-sdk_r10-windows\android-sdk-windows\platform-tools>adb pull /data/data/com.yourpackage.yourapp/files/yourfile.xml
Note: I have only tried this on the emulator, I don't know how to use adb with a physical phone.
You need to root your phone to see Context.MODE_PRIVATE files
It ends up being stored in data//files I believe but you need root permission to see them
So either root your phone or wait until you finished debugging and then add Context.MODE_PRIVATE
If Eclipse is used, there is one more option:
DDMS Perspective > File Explorer tab > data/data/com.yourpackage.yourapp/files
where you can pull/push/delete files.
Another option is to have a command in the app that dumps the private files. This only works if you don't want to edit the files, but has the added bonus that you don't have to strip it out before it goes to production, because the user can't break anything with it. Well, as long as the files don't contain sensitive information. But, really, if they do, you're doing something wrong. As #user1778055 said, a user can root their phone to access it.
I have created a directory in my app's internal storage (/data/data/com.my_app) and gave global read/write permissions to the directory via the method
context.getDir(DATA_DIR_NAME, Context.MODE_WORLD_READABLE | Context.MODE_WORLD_WRITEABLE);
Through my app, I verified that the linux file permissions are correct:
drw-rw-rw- app_71 app_71 2010-11-16 18:38 app_data
And I was able to read/write files in-to/out-of the directory app_data just fine. However, one of my developers suddenly wasn't able to write to the directory anymore. Our application has trouble accessing the directory on his device as well.
The strange thing is that the file permission for the directory is still the same. We can't do any sort of writes to the directory, and we can't read any files within the directory anymore either (the files were given global rw permission previously).
The only thing we can do is adb shell ls /data/data/my_app/app_data to see our list of files. Doing adb shell ls -l /data/data/my_app/app_data strangely doesn't return anything. And we can't CD into the directory either.
Does anyone have any pointer on what the problem is or how to solve this? We are at our wit's end.
Much appreciated.
Directories need to have the execute (X) bit set to be able to access the contents of the directory. I don't know the android modes, but look for MODE_WORLD_EXECUTABLE and see if you can set that.
Basically, you need mode 0777 (rwxrwxrwx) for a directory to be globally accessed with all permissions.
The reason ls works is that you have permission to read the filenames in the directory. ls -l does not work, because you cannot access the files in the directory to get the metadata that -l will print.