I was attempting to access the data data folder of an application without rooting . I followed How to access data/data folder in Android device? and was able to access the folder.
Now I was trying to copy the required file from data/data to a folder in my SD Card , however I get a permission denied on it. In the thread I have referenced above , no body complained of this behaviour so I suppose it shouldn't happen at my end too .
This is exactly what I am doing
C:\AndroidSdk\platform-tools>adb shell
shell#D6503:/ $ run-as com.xxx.xxx
run-as com.xxx.xxx
shell#D6503:/data/data/com.xxx.xxx $ cp databases/xxx.db /storage/sdcard1/Pictures/
cp: /storage/sdcard1/Pictures/xxx.db: Permission denied
I have verified that the folder /storage/sdcard1/Pictures is accessible through shell.
Happened to me as well. This is what I did to access the contents of the data folder of my app in my Nexus 5 (Android 5.0), without having root access or chmoding any file:
Open a console where your ADB is located and execute:
adb backup -noapk com.your.packagename
You will be asked to accept the backup on your device. Accept it and don't use any password. Once the backup process is completed, you will have a file with .ab extension on your ADB folder.
The backup will be compressed in a special way, you can decompress it with this tool: Android Backup Extractor
To use it, unzip it and put the backup file (*.ab) on the same folder where the extractor (abe.jar) is. Then open a console there and execute the following command:
java -jar abe.jar unpack NAME_OF_BACKUP.ab NAME_OF_BACKUP.tar
Notice that the result of this operation will be a *.tar file, which can be opened or decompressed with WinRAR or many other compression tools.
OPTIONAL for SQLite Databases: If you want to see the contents of the database, you can use this Firefox plug-in: Firefox SQLite Manager
Related
If you attach android device to PC you can browse files and dirs. It is possible to get this directory using Environment.getExternalStorage(). You can use it from your application and create accessible files and dirs. It works fine.
On my devices this path looks like /storage/emulated/0 and if i try adb push to this directory i will get access denied error. Is it possible to copy files using adb to the same folder as Windows Explorer does?
D:\...\tools>adb push ACCOUNTS.DB /storage/emulated/0
failed to copy 'ACCOUNTS.DB' to '/storage/emulated/0': Permission denied
58969 KB/s (606505 bytes in 0.010s)
I'm implementing automated import/export and i want files to be accessible without adb shell in case anything will go wrong.
Currently using variable$EXTERNAL_STORAGE as workaround, it works for both adb and application.
Device: Asus Fonepad 7, Android 5.0, tried Genymotion Custom Tablet 6.0 - works.
Try to use /sdcard/. Although it is strongly discouraged to do this in code. It seems to be the only way with adb :
$ adb push somefile /storage/emulated/0/somefile
[100%] /storage/emulated/0/somefile
adb: error: failed to copy 'somefile' to '/storage/emulated/0/somefile': Read-only file system
$ adb push somefile /sdcard/somefile
[100%] /sdcard/somefile
By the way, on my device they don't have the same value : Environment.getExternalStorage() points to /storage/emulated/0/ while /sdcard points to /storage/emulated/legacy.
It's pretty easy, internal storage is unavailable on non-rooted devices. So as was mentioned in bwt answer you just need to push your data to sdcard :
adb push somefile /sdcard/somefile
With retrieving files from your filesystem you'll also have few problems. But with the case of pulling a database from a debug application - you'll just need to change file permission via chmod.
Here you have a useful link - XDA guys about adb
I am practicing to create a system app and testing using a rooted device. The application copies files(images,music and video) from a zip file to a the directory /data/media/0/SampleFolder. But after the files are copied, they are not recognized or can not be opened when viewed using ES File Explorer File Manager.
When I view via adb shell and enter the command ls -l /sdcard/SampleFolder/, the files are then recognized and they can be opened after entering said command. If not mistaken, the paths data/media and sdcard have symbolic links.
Does this mean that there is a sync problem between /data/media and /sdcard/ and if yes, is there a way to refresh it programmatically?
Note: The following have been tried but have not been successful:
Rebooting the device
entering ls -l command programmatically
called MediaScannerConnection.scanfile for each file in the /sdcard/SampleFolder directory
broadcasting Intent.ACTION_MEDIA_MOUNTED in Environment.getExternalStorageDirectory
broadcast Intent.ACTION_MEDIA_SCANNER_SCAN_FILE for each file in the /sdcard/SampleFolder directory
HI I am developing an android application for android on nexus 7 device.
I am trying to copy my database.db from assets to /data/data/myPackage/databases/ folder. Nothing wrong till here. No exceptions and everything runs smoothly.
But When i try to get into /data/data/ folder through adb shell or with file explorer it says permission denied or just doesnt show anything.
Am I missing something here ?
PS: myPackage is just symbolic i have my own package name in its stead
Command line is here
shell#tilapia:/ $ cd /data/
shell#tilapia:/data $ ls
opendir failed, Permission denied
You need to have your device rooted to be able to access that folder.
If you want to look at your database you can always export it to the sdcard and look at it there.
see this link for an example on how to do that
trying to export db to SDCARD
you can always get the db out of the emulator, but never from a live device or else it would be easy to write apps that read/write other apps' databases and create malware
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.
For debugging purposes, I wanted to have a couple of mp3 files located somewhere "in" my android emulator. Is there anyway to directly push files from my OS file system to the storage system of android?
If so, which directory does android keep audio files?
if not, how can I access an SD card via emulator?
[update2]: The problem in update1 solved. Should use adb push.
[update1]: I followed kgiannakakis's advice to create an sdcard for my avd. However, I got Permission denied error when I try to create new directory inside it.
$ cd sdcard
$ ls
LOST.DIR
$mkdir musics
mkdir failed for musics, Permission denied
$ su mkdir musics
su: uid 10016 not allowed to su
You can find directions for emulating an SD card here.
I believe that the easiest way to copy files to the SD card is to use the adb utility.
See here for a more advanced solution.
Regarding instructions at http://android-er.blogspot.com/2009/10/create-sd-card-in-android-emulator-and.html on creating the 'pictures' folder, you can run the same commands from the adb shell, instead of running them from inside the emulator.
So get a command line at e.g. C:\Program Files (x86)\Android\android-sdk-windows\platform-tools (on 64bit windows), and run adb shell.
Then you can run the same commands:
#cd sdcard
#mkdir pictures
and create the directory successfully with no permission denied error.
Following same instructions, in DDMS I had to browse to \mnt\sdcard to find the SD card volume.