Viewing private files created by an android app - android

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.

Related

ADB push folder from Windows to internal app storage

I'm trying to move all sub-folder of a folder on my desktop to the 'files' folder in the internal app storage of the app I developed.
My first attempt with one file:
/e/Android/android-sdk/platform-tools
$ adb push pull.sh /data/data/irisrecognition.example.com.irisrecognition
failed to copy 'pull.sh' to 'C:/Program Files/Git/data/data/irisrecognition.example.com.irisrecognition': No such file or directory
26 KB/s (315 bytes in 0.011s)
Why does the GIT path gets added to my data path? I also tried using adb shell, run-as etc to no avail.
Here is what worked for our App:
Ensure the device is connected.
Open a console.
Finally, run something like:
adb push C:\my-location\my-data\. /storage/emulated/0/Android/data/my.package.name
But edit above's paths to your requirements (specially the "my.package.name" part).
Note that the "." dot means current-directory, but by putting "C:\my-location\data\" in front of it, we mark that path to be current.
Also, the destination-directrory is auto created (if it does not already exist).
You can't simply push or pull files into or from the internal storage of an app. If it would have been possible, any 3rd party app could fetch or inject data into an app's private storage space.
If you really want to do this, you need to have root access.

How to access android root directory

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

How do I view Android application specific cache?

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);

Root Android phone

I have created a database for my app and I want to check .db folders to check the data inserted while developing. But my Android mobile will not allow to access data folder. To achieve this I have rooted my mobile with GingerBreak.apk. Device rebooted but nothing happened. How can I check my data base from my phone.
Note: I can't check the data using emulator, because app cant run on emulator, it uses, Bluetooth, WiFi,etc.
Regards,
Krishna
You need to install some file broswer(such as R.E file manager) to access to these .db files. They are located in /data/data/{package name} dir.
Meanwhile, you can access these file via command line.
For emulator:
Type adb shell in the command line, and you can see a "#" prompt.
Type 'cd /data/data/{package name}` to go to the very dir where the
.db file is located.
Now type sqlite3 <db file name, no extension> so that you can execute SQL command to read and control the .db file. Now you can see a "sqlite>" prompt.
For real device(phone must be rooted):
Step 2 and 3 are the same. In Step 1, you have to type "adb shell", and then "su" to see the "#" prompt.
Hope it helps.
To root your phone. You can use lucky patcher app.Although there are plenty of apps available around internet but i found it worth using
By using this app you can not only root your device as well as remove annoying ads and much more.

android emulator copy files in system partition

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/.

Categories

Resources