Extract Android SQLite Databases For Contacts, SMSs, Etc - Android Software Development

Hi All,
I'm a Windows/Web/Database developer and I've decided to bite the bullet and learn some Java and write apps for Android. I've done Hello World and a few other programs and now I want to start playing with things like contacts and SMSs.
To make life easier I want to get copies of the various SQLite databases so that I can write my SQL queries and general play with them in my SQLite admin program on Windows.
I assume that they are just regular SQLite files like I've used in other projects so what I'd like to know if possible is:
Is my assumption about them being regular SQLite files correct?
Where do they live on the phone?
How do I get them off the phone/emulator?
Also, I don't know whether it makes a difference to what I want to do but I've not rooted my phone and don't really want to. Based on that, if it needs rooting to get them I'd be really grateful if anyone happens to have gone through this exercise before and can just attach them to a reply post.
Thanks for your time in advance

For anyone who's interested, after a load of digging I've found the following:
Contacts = /data/data/com.android.providers.contacts/databases/contacts.db
SMS = /data/data/com.android.providers.telephony/databases/mmssms.db
Bookmarks = /data/data/com.android.browser/databases/browser.db
You can get them off the emulator using the adb pull command. E.g.
adb pull /data/data/com.android.providers.contacts/databases/contacts.db d:\contacts.db
Cheers

k420 said:
For anyone who's interested, after a load of digging I've found the following:
Contacts = /data/data/com.android.providers.contacts/databases/contacts.db
SMS = /data/data/com.android.providers.telephony/databases/mmssms.db
Bookmarks = /data/data/com.android.browser/databases/browser.db
You can get them off the emulator using the adb pull command. E.g.
adb pull /data/data/com.android.providers.contacts/databases/contacts.db d:\contacts.db
Cheers
Click to expand...
Click to collapse
Adding one for Calls :
Calls -
Code:
/data/data/com.android.providers.contacts/databases/contacts2.db
Example to access :
Code:
[email protected]:/ # sqlite3 /data/data/com.android.providers.contacts/databases/contacts2.db
providers.contacts/databases/contacts2.db <
SQLite version 3.7.11 2012-03-20 11:35:50
Enter ".help" for instructions
Enter SQL statements terminated with a ";"
sqlite> .headers on
.headers on
sqlite>.mode column
.mode column
sqlite> select _id,number+random(),duration,name contact_name ,datetime(date/1000, 'unixepoch', 'localtime') timestamp
from calls
where number not like '1832%'
order by _id desc
limit 0 , 6 ;
_id number+random() duration contact_name timestamp
---------- -------------------- ---------- ------------ -------------------
16396 -7814232970342288419 0 2016-03-16 14:59:53
16395 -2897789212886021933 112 2016-03-16 14:27:11
16393 -5099152494103830835 262 Rajaselvam M 2016-03-16 12:28:56
16389 8412659988096325402 13 2016-03-16 09:36:48
16385 1480282204589577101 125 அம்ம 2016-03-16 08:05:07
16384 -1575337348523869115 0 Saami 2016-03-15 22:05:50
sqlite>

this is great, i dont suppose you have some code to extract sms and contacts as well do you.
i copy pasted your above code into db browser for sqlite and it worked great.
but i do not know how to write the code myself

I lost my android device but need the contacts from it...HELP!
is there any way i can extract this data from my Mac computer or do I have to do it from the android device? cause I lost the actual phone and for some reason the last month or so of contacts inputted werent backed up to my google account.

[email protected] said:
is there any way i can extract this data from my Mac computer or do I have to do it from the android device? cause I lost the actual phone and for some reason the last month or so of contacts inputted werent backed up to my google account.
Click to expand...
Click to collapse
You have to grab the actual file in order to read your contacts. The only way you'd have it on your mac is if you did a root backup of your phone.

Related

[Q] How to get the version number of ClockWorkMod Recovery with PC cmd lines?

Hi, everyone
I'm now working on a program about flashing roms on PC, and I'd like to call it "Rom Manager" on desktop But now, i get one problem. It's that, how to get the version number of ClockWorkMod Recovery with PC in cmd lines
Any help please?
Thx in advance!
One way I've spotted is to look inside
/data/data/com.koushikdutta.rommanager/databases/settings.db
It's the standard SQLite format:
Code:
0000fa0: 2203 033d 1b63 7572 7265 6e74 5f72 6563 "..=.current_rec
0000fb0: 6f76 6572 795f 7665 7273 696f 6e32 2e35 overy_version[B]2.5[/B]
0000fc0: 2e30 2e37 1602 032b 1569 735f 636c 6f63 .[B]0.7.[/B]..+.is_cloc
0000fd0: 6b77 6f72 6b6d 6f64 7472 7565 2201 0331 kworkmodtrue"..1
You can see 2.5.0.7 (which is my recovery version) in there. I haven't time to debug it further, so I thought I would perhaps offer a way out for you.
Edit:
Probably easier on the eye:
$ sqlite3 settings.db
SQLite version 3.6.22
Enter ".help" for instructions
Enter SQL statements terminated with a ";"
sqlite> select * from settings where key='current_recovery_version';
current_recovery_version|2.5.0.7
sqlite>
Thank you! Now i can find the recovery version number in the database of android rom manager app. But i think there must be a lot of my users don't have a rom manager app in their phone, and then i can't get it with the database. So, is there another way to get it without the android rom manager app?
Thx anyway!
You'll have to test this if this is true without the app.:
Code:
# cat /sdcard/clockworkmod/.settings
{"paypal_transaction_id":"","is_clockworkmod":true,"readonly_recovery":true,"current_recovery_version":"[B]2.5.0.7[/B]","recovery_timestamp":1284679575253,"detected_device":"bravo","reboot_recovery":""}
My God!! It works!!
I'm sorry that i almost forget this thread, but now it gives me a big surprise!
Thanks Man, you're great!!

Help with creating keystore...please

Hey everyone...I can't seem to find any help on creating a keystore. I created my first live wallpaper and have the apk, but I cant upload to the market until I create a keystore and sign the apk. I don't know how to do this. I have the jdk and sdk installed, along with Eclipse, but all the tutorials out there are way above my head.I don't know anything about java code and all tutorials assume that I do. Is anyone willing to help walk me through this? I don't even know how to get my apk file into Eclipse properly to start. Any help is appreciated.
* to make key
enter this into cmd prompt: cd C:\Program Files\Java\jre1.6.0_01\bin
and then this: keytool -genkey -v -keystore C:\Program Files\Java\jdk1.6.0_23\bin\keystore1.keystore -alias (your name) -keyalg RSA -validity 10000
*then to sign apk
(this is how I do it)
1.copy/paste the apk onto your desktop
2. change the extension to .zip
3. open the now .zip file
4. delete the "META-INF" folder
5. convert it back to .apk
6. open cmd prompt
7. paste this in (without quotes): "cd C:\Program Files\Java\jdk1.6.0_23\bin " (change the path if you have to first)
8. then paste this: "jarsigner -verbose -keystore (pathway to key file) C:\Users\(name of user)\Desktop\(appname).apk (name of key)"
*that is to sign it, not sure if that will work or if your key saved properly when you tried, let me know
It took me about 8 hours to figure it out when I first started too
yeah, or you could just use eclipse
go to file -> export project
and then it'll walk you through the whole process
it takes like 30 seconds
it still amazes me the number of people who do not know this
it's about 500 times easier if you just do it in eclipse
you can spend 8 hours trying to figure it out like hyperbyte did
or you can just use eclipse and be done in a few minutes
smaskell said:
yeah, or you could just use eclipse
go to file -> export project
and then it'll walk you through the whole process
it takes like 30 seconds
it still amazes me the number of people who do not know this
it's about 500 times easier if you just do it in eclipse
you can spend 8 hours trying to figure it out like hyperbyte did
or you can just use eclipse and be done in a few minutes
Click to expand...
Click to collapse
WOW really!? Why the heck didn't anyone else tell me that!? LOL I'm gonna try it now. Thanks for quick responses.
StoopidNoob said:
WOW really!? Why the heck didn't anyone else tell me that!? LOL I'm gonna try it now. Thanks for quick responses.
Click to expand...
Click to collapse
You can also right click on the project and go to Android Tools > Export signed application package
hyperbyteX's method also doesnt zipalign the package which the export wizard does and is reccommended.
http://developer.android.com/resources/articles/zipalign.html
Eventually advanced users would want to use an ant build script (and possibly proguard to optimize) but the export tool is fine for most stuff.
alostpacket said:
hyperbyteX's method also doesnt zipalign the package which the export wizard does and is reccommended.
http://developer.android.com/resources/articles/zipalign.html
Eventually advanced users would want to use an ant build script (and possibly proguard to optimize) but the export tool is fine for most stuff.
Click to expand...
Click to collapse
alostpacket said:
You can also right click on the project and go to Android Tools > Export signed application package
Click to expand...
Click to collapse
And this is going to let me publish in the market?? For sure?? LOL I'm sorry. Been going in circles with this. I'm completely new to Droid and everything that comes with it.
StoopidNoob said:
And this is going to let me publish in the market?? For sure?? LOL I'm sorry. Been going in circles with this. I'm completely new to Droid and everything that comes with it.
Click to expand...
Click to collapse
My method is just a different menu/way to get you to the same "export wizard" as smaskell reccommended.
And yes, once signed, you should be able to publish to the market.
Ok this is gonna sound even more stoopid...but how do I package the apk? I used a program someone provided and it automatically made the .apk file for me, which I was able to upload and install in my inspire, but I assume there's more to it than just exporting the .apk itself right?
There are basically two keys developers come across when developing.
1) The debug key that comes with the SDK and just allows devs to test their apps
2) Your private personal developer/publisher key (that you generate yourself)
In eclipse whenever you build the project it makes an apk signed with the debug key (you can't use this to install on other devices unless they have debugging enabled and cannot upload to the market with this key). This is just a standard key built into android for debugging.
When you go through the export wizard that we posted, it will save an apk that is signed with your key. You can give this apk to others to sideload and upload to the market. It will also help you generate a key and alias and password if you havent generated one before.
Whatever you do, SAVE your key and and remember your alias and password and do NOT give it out to anyone else.
This is how the market will know that an apk comes from you. If you lose this key, you wont be able to upload new versions under the same package name.
hope that helps.
Also, in your manifest.xml make sure you have
Code:
android:debuggable="false"
in the <application> tag
example:
Code:
<application
android:icon="@drawable/my_icon"
android:label="@string/app_name"
android:debuggable="false" >
<!-- your acitivities, services, and broadcast recivers are here-->
</application>

[UPDATE 2/12/2010] Terminal IDE - Full 'on device' Java / Android IDE

[UPDATE]
BusyBox 1.19.2
Bash 4.2
Midnight Commander 4.8
TMUX 1.5 - That's right, full terminal multiplexer..
Vim 7.3
Terminal IDE ASCII Soft keyboard first round bug fixes complete.
It's the addition of TMUX and MC that really excites..
--------------------------
Well,
As the only people I know who might even be interested in this, I would like to announce the release of Terminal IDE v1.0.
A complete Java / Android Development Environment that runs on the device itself, with a nice telnetd / sshd feature.
For Android. Of course... Eat this you IPhone Hounds..
Woo HOO!!
The application is available on Android Market.
https://market.android.com/details?id=com.spartacusrex.spartacuside
As what I can only describe as 'dark days' finally draw to an end, I am very pleased with this first draft.
PLEASE give it a go, log in over telnet for a smoother ride, and let me know how it goes..
DO THE TUTORIAL! Does it work ?!
I have released the whole project GPLv2! Yeah, Who Knew!?
http://code.google.com/p/terminal-ide/
BOOOOOM!
Spartacus
a link to the app in the market would be usefull.
Interesting. Was just wondering about coding on my tablet.
Pretty freakin sweet
Thanks for putting this out!
Awesome
The full keyboard alone makes it worth downloading, but the IDE as well - wow!
this is best bro.
I randomly found this last night while looking for a decent mobile IDE for my tablet. I was looking for a simple text editor with syntax highlighting and you've taken that extra step to include other tools for ssh, telnet and compilers. Much appreciated.
One question, how do you start the ssh server? sshd doesn't seem to do it. I would like to scp files to my device from my desktop in order to work on my commute.
Thanks
The sshd app is actually called Dropbear.
You also have Dropbearkey.
You use Dropbearkey to generate the sshd certificates you need.
I really need to add a tutorial on setting the sshd keys up
For now Google has a couple of articles on it.
For file transfers you also have busybox FTP but I admit not terribley secure..
Allthough SSH is provided, and I wonder whether an SSH pipe can be created..?
And lastly you can just copy the files over to your sdcard via USB..
Will look into it & add tutorials asap.
Ok. So I now have SSHD working..
But there is a slight issue.. basically when you log in you have to start bash manually.. unless you have the file /etc/shell with the correct shell to use.. Which requires a rooted phone.
Since Terminal IDE is for non-ROOT users, I will have to recompile the code to allow a shell to be specified on the command line.. Soon..
FOR NOW - This is how to connect to the phone via SSH (There are other ways using public keys but this is one way)
So - Once in Terminal IDE
2) You need to create a couple of server ssh keys
Start in $HOME
Code:
cd ~
Create folder
Code:
mkdir .ssh
Give it some secure permissions
Code:
chmod 700 .ssh
Get in there
Code:
cd .ssh
Now create the keys
Code:
dropbearkey -t dss -f dropbear_dss_host_key
dropbearkey -t rsa -f dropbear_rsa_host_key
ok - That's almost it. Just need to start dropbear with the correct parameters now. [Probably want to keep this in a script]
Back HOME
Code:
cd ~
You need to know the UID of your app, which is different per phone - use 'id'
Code:
id
That will tell you your user ID / Group ID. Let's say its 10058.
Now to start DropBear
Code:
dropbear -A -N username -U 10058 -G 10058 -C password -d ~/.ssh/dropbear_dss_host_key -r ~/.ssh/dropbear_rsa_host_key -F -E -p 8090 -P PidFile
This will start it running in the foreground with password set to 'password' on port 8090.
Then you can connect, like telnet, and simply use 'password' for the password.
Now for the issue. It will start a simple shell session in / with no ENVIRONMENT variables or anything..
I'll fix it permanently in a future release, but for now it can be fixed with these 2 commands.
cd into your home dir - Check this is correct on your device
Code:
cd /data/data/com.spartacusrex.spartacuside/files
And start bash with an init file Terminal IDE auto-magically creates..
Code:
./system/bin/bash --init-file ./.init
Everything should now be setup as usual.
Good luck..
Very awesome and thank you sir. Works like a charm.
One thing to clarify for those "braving" this (not that it's all that insane to try)... the '-N' is setting the username (in the case of the example, setting it to 'username').
Also, it gives a permission denied for scp, I'm assuming since it doesn't init/run the shell. Should be fine since FTP is included. Haven't tried this option yet. Not too worried about security at the moment, since I'll only run it on a private network.
May I make a (maybe) small feature request? Is it possible to include a "keep screen awake" option in the options menu? I have my Xoom config'd to turn off the wifi when the screen is off for power saving (can go ~4 days on 1 charge), so it will kill my connections if I let this happen. I know not everyone has this config set, but it'd be a nice option.
NOW, if I wasn't lazy, I could probably add this myself and build since I've dl'd the source. But, lazy and working on a few projects already.
Again, much thanks.
And as if by magic..
Funnily enough I was having the exact same issue last night while using wget to transfer a big file to my device..
NEW VERSION UPLOADED v1.13
Now has 3 non-exclusive lock types available in the options :
- CPU Lock
- SCREEN Lock
- WIFI Lock
Set them as you wish...
Saw that this morning when I was on the bus (Thursday morning here in Hong Kong). Very awesome and much appreciated.
As well, thanks for open-sourcing it. +1 for you sir!
Very cool stuff
Thanks for creating this.
Great app! However I can't compile .java files. I always get an error that it can't unzip a file in /android.policy.jar. Any idea?
Sent from my GT-I9100 using XDA App
Do you think its possible to also support compiling C sources directly in your phone
I've been searching for this ever since I got an android.
THANK YOU.
Says that it's incompatible with my OG Droid. Any idea why?
shpen said:
Says that it's incompatible with my OG Droid. Any idea why?
Click to expand...
Click to collapse
Most likely seems to be due to the ROM you are using and/or the market version
can u post the build.prop here?
/system/build.prop
also, try going back to market 2.x, 3.x market(s) do loads of checks
Does anybody know why I can't compile java files? I always get the following error:
Error reading /system/framework/android_policy.jar cannot read zip file.
Any ideas? Could anyone upload there android_policy.jar because that might cause the error.
Sent from my GT-I9100 using XDA App
Hi Schindler33.
Can I ask, have you followed the tutorials, say the first helloworld example TO THE LETTER?
Does the helloworld example work?
The parameters have to be correct, and as always exact, and the BOOTCLASSPATH variable must be set.
If so, is it a custom ROM?
Does that policy jar file exist and is it readable by non root users?
As much info as possible good..

What is ".LSBackgroundService"

Hi,
I use Watchdog which alerts me when processes use a lot of resources. Recently, a process ".LSBackgroundService" has been popping up soon after a reboot. I've searched high and low but can't find anyone mentioning that process anywhere. I looked for apps on my phone that have something like LS in the titles but found nothing.
Killing the process doesn't help; it just restarts itself. Also, I have a rooted SM-N900V (Verizon Note 3) running Kit Kat 4.4.2.
Does anyone know what this process might be or how I can narrow down the culprit app?
Thanks!
feretio said:
Hi,
I use Watchdog which alerts me when processes use a lot of resources. Recently, a process ".LSBackgroundService" has been popping up soon after a reboot. I've searched high and low but can't find anyone mentioning that process anywhere. I looked for apps on my phone that have something like LS in the titles but found nothing.
Killing the process doesn't help; it just restarts itself. Also, I have a rooted SM-N900V (Verizon Note 3) running Kit Kat 4.4.2.
Does anyone know what this process might be or how I can narrow down the culprit app?
Thanks!
Click to expand...
Click to collapse
Apps and the system itself generally have pieces of that run checking for events to happen. Each program can name those services anything they want. For example, an email program can check to see if there's new mail every so often even if the mail app is not in the foreground. Most, if not all services do not have a user interface, thus you can't interact with it.
There's an app on Play called Disable Service that can show you which app has what background services.
You could use something like that to check to see which app spawned the .LSBackgroundService
Sent from my SM-N900V using Tapatalk
at the end of the day, all those apps/services are just processes.
More importantly, every package (or groups of .apks which declare the same "sharedUserId" and are signed by the same key) have a distinct user identity "silo". That's the basic Android security paradigm.
So why not just do a "ps" command, find the service process in that list, and then match the "u0_aNNN" identity of that service to it's package? **
Hint: look at the 2nd column of /data/system/packages.list ; it's the numeric value of the user ID (=uid)
So for instance, "u0_a80" (what you see in the ps output) == "10080" (2nd column of /data/system/packages.list).
Find the process -> find the symbolic userid -> 2nd column of /data/system/packages.list == package name.
From the package name, you get back to the APK name with:
Code:
pm list packages -f
It is helpful in all of the above to know what "grep" does.
In this strategy, one possibility is that the user name is "system" - in which case there are probably many many .APKs involved (in either /system/app or /system/priv-app) all which share a common "sharedUserId". But at least at that point you have eliminated all market apps.
There are some market apps that let you browse the manifests & look at service definitions of installed apps - market apps for sure ( but possibly not every one of the system pre-installed apps. )
If you are root however, you have access to every last .apk on the device. If you have the patience you can certainly:
- grab all of the apks and move them to a PC
Code:
adb shell
su
mkdir /sdcard/all-system-apks
cd /system
find app priv-app -name '*.apk' -print | while read fnam ; do cp $fnam /sdcard/all-system-apks/ ; done
exit
exit
adb pull /sdcard/all-system-apks/
- extract the (binary) AndroidManifest.xml file (using "unzip")
Code:
ls -1 *.apk | while read fnam ; do
unzip $fnam AndroidManifest.xml
bnam=`basename $fnam .apk`
mv AndroidManifest.xml AndroidManifest-${bnam}.xml
done
- convert the AndroidManifest files from binary format to plaintext:
Code:
ls -1 *.xml | while read fnam ; do
java -cp /home/user/AndroidXMLDecompress [URL="https://pastebin.com/raw/feuwAKCf"]AndroidXMLDecompress[/URL] $fnam | sed -e 's#>#>\n#g' > plaintext-$fnam
done
- if you know the service name you are after, then
Code:
find . -name 'plaintext-*xml' -exec grep -l $SERVICENAME {} \;
Now, who's afraid of the command line? ***
** if you can't resolve something to a single entity, you can still use process of elimination.
*** even if you are a Win-doze fanboi, you can still use cygwin for all of this.

Kotlin app can't find file even though it exists

I'm working on a Kotlin app where I need to access the Cookies file located at /data/data/com.android.chrome/app_chrome/Default/Cookies. However, when I try to access the file, I get a "file not found" error, even though the file definitely exists at that location.
I've double-checked the file path and made sure there are no typos (I can see the file with adb shell and Amaze File Manager), and I've also checked that the app has permission to access the file (app has root permissions).
First I was trying to open and read the file directly and I got the error:
CODE at https://stackoverflow.com/questions/76064385/kotlin-app-cant-find-file-even-though-it-exists
I though maybe Chrome was running so I couldn't open the file directly so I tried copying it to a temp folder and reading that:
CODE at https://stackoverflow.com/questions/76064385/kotlin-app-cant-find-file-even-though-it-exists
But that still fails:
CODE at https://stackoverflow.com/questions/76064385/kotlin-app-cant-find-file-even-though-it-exists
Is there anything else I can try to troubleshoot this issue?
Something in the code triggers cloudflare and blocks me from posting
Code:
Sorry, you have been blocked
You are unable to access xda-developers.com
Why have I been blocked?
This website is using a security service to protect itself from online attacks. The action you just performed triggered the security solution. There are several actions that could trigger this block including submitting a certain word or phrase, a SQL command or malformed data.
What can I do to resolve this?
You can email the site owner to let them know you were blocked. Please include what you were doing when this page came up and the Cloudflare Ray ID found at the bottom of this page.
Cloudflare Ray ID: 7badda7c6b9486c6 • Your IP: Click to reveal • Performance & security by Cloudflare
SQLite definitely won't open the file. So, your decision to copy it was right.
Firstly, try to split the single command string into an array.
The documentation for ProcessBuilder class has an example:
ProcessBuilder pb = new ProcessBuilder("myCommand", "myArg1", "myArg2");
Or try to use SuFile from the libsu, for example:
AndroidIDeditor/Util.java at 6a62bac0e3e63502e9a7b538217f65189ff85fa4 · sdex/AndroidIDeditor
Android Device ID changer. Contribute to sdex/AndroidIDeditor development by creating an account on GitHub.
github.com
lioce said:
SQLite definitely won't open the file. So, your decision to copy it was right.
Firstly, try to split the single command string into an array.
The documentation for ProcessBuilder class has an example:
ProcessBuilder pb = new ProcessBuilder("myCommand", "myArg1", "myArg2");
Or try to use SuFile from the libsu, for example:
AndroidIDeditor/Util.java at 6a62bac0e3e63502e9a7b538217f65189ff85fa4 · sdex/AndroidIDeditor
Android Device ID changer. Contribute to sdex/AndroidIDeditor development by creating an account on GitHub.
github.com
Click to expand...
Click to collapse
Seems like not even like that can I read the Cookies file from Chrome
Code:
fun copyFile(source: String, destination: String) {
Log.d("CookieSwapLogger", "copyFile '$source' to '$destination'")
val sourceFile = SuFile(source)
if (sourceFile.exists()) {
Log.d("CookieSwapLogger", "sourceFile.exists")
} else {
Log.d("CookieSwapLogger", "sourceFile.notExists")
}
---------------
2023-04-21 18:20:47.440 6347-6347 CookieSwapLogger com.david.cookieswapper D copyFile '/data/data/com.android.chrome/app_chrome/Default/Cookies' to '/data/user/0/com.david.cookieswapper/app_temp/Cookies'
2023-04-21 18:20:47.492 6347-6347 CookieSwapLogger com.david.cookieswapper D sourceFile.notExists

Categories

Resources