[Q] Android App SQLite Database Creation - Where? - Android Software/Hacking General [Developers Only]

Ok, I don't get it.
Porting CM7 and I have an odd one - the stock email application blows up when an account is added. Tracing it down I found the problem - the Sqlite schema is defective. Here's what I have in /data/data under the appropriate directory, examined by Sqlite3
sqlite> .schema account
CREATE TABLE Account (_id integer primary key autoincrement, displayName text, emailAddress text, syncKey text, syncLookback integer, syncInterval text, hostAuthKeyRecv integer, hostAuthKeySend integer, flags integer, isDefault integer, compatibilityUuid text, senderName text, ringtoneUri text, protocolVersion text, newMessageCount integer, securityFlags integer, securitySyncKey text, signature text, accountColorinteger);
Note the last field. There's supposed to be a space there; when the table was created the type statement was obviously keyed next to the field name without the required space. It also appears that SQLite is perfectly happy to create a field in a table without an explicit type declaration, which disturbs me, but it is what it is.
Here's the thing - obviously somewhere there's a declaration of that variable and type in some file somewhere. Right?
Well, where is it then - because I can't find it with a complete pass through the source using find / grep!
Nevermind - found it. The android guys were cute with the defines in the code and it indeed was a missing space in the email provider source.....

Related

Solving problem with transfer of Nokia calendar to an Android phone

First of all I would like to say hello to everyone as this is my first post to this forum
I have android phone (HTC Desire Z) for about a week now an I just have to share how insanely awesome this device is! To show you what I mean I'll describe how to fix the problem with incorrect transfer of calendar notes from my old Nokia N95 8GB to new HTC.
I rooted my HTC and uploaded newest Sense ROM (2.1) with Android 2.3.3 from the forum (thanks for making that possible!).
Now, to the problem. I wanted to transfer calendar notes from N95 to my new phone (more than 200 of them). Using the transfer application, the notes got copied but all had lost their alarms! This was disaster for me as I'm depending on these notes on daily basis. I googled for this problem but didn't find any solution. But this is the Android - everything can be done, right?
So, the solution. I've read somewhere that Android stores data of all it's applications as sqlite databases. As I professionally work with sql databases this seemed to be to good to be true... But no, it is true
To the point then. It is possible to fix my calendar by executing sql queries directly against the database itself!
I've found and pulled the calendar database file from the device by
Code:
adb pull /data/data/com.android.providers.calendar/databases/calendar.db
and got inside
Code:
sqlite3 calendar.db
Let's see what tables we have
Code:
.tables
Code:
Attendees EventsRawTimes android_metadata
CalendarAlerts ExtendedProperties easSyncInfo
CalendarCache Instances easTracking
CalendarMetaData Reminders pcscSyncInfo
Calendars _sync_state pcscTracking
Events _sync_state_metadata view_events
Interesting tables are Events and Reminders. Let's extract their ddls
Code:
.schema Events
.schema Reminders
Code:
CREATE TABLE Events (_id INTEGER PRIMARY KEY AUTOINCREMENT,_sync_account TEXT,_sync_account_type TEXT,_sync_id TEXT,_sync_version TEXT,
_sync_time TEXT,_sync_local_id INTEGER,_sync_dirty INTEGER,_sync_mark INTEGER,
calendar_id INTEGER NOT NULL,htmlUri TEXT,title TEXT,eventLocation TEXT,description TEXT,
eventStatus INTEGER,selfAttendeeStatus INTEGER NOT NULL DEFAULT 0,commentsUri TEXT,
dtstart INTEGER,dtend INTEGER,eventTimezone TEXT,duration TEXT,allDay INTEGER NOT NULL DEFAULT 0,
visibility INTEGER NOT NULL DEFAULT 0,transparency INTEGER NOT NULL DEFAULT 0,
hasAlarm INTEGER NOT NULL DEFAULT 0,hasExtendedProperties INTEGER NOT NULL DEFAULT 0,
rrule TEXT,rdate TEXT,exrule TEXT,exdate TEXT,originalEvent TEXT,originalInstanceTime INTEGER,
originalAllDay INTEGER,lastDate INTEGER,hasAttendeeData INTEGER NOT NULL DEFAULT 0,
guestsCanModify INTEGER NOT NULL DEFAULT 0,guestsCanInviteOthers INTEGER NOT NULL DEFAULT 1,
guestsCanSeeGuests INTEGER NOT NULL DEFAULT 1,organizer STRING,deleted INTEGER NOT NULL DEFAULT 0,
dtstart2 INTEGER,dtend2 INTEGER,eventTimezone2 TEXT,syncAdapterData TEXT, importance INTEGER NOT NULL DEFAULT 1,
iCalGUID TEXT,last_update_time TEXT,parentID INTEGER,facebook_source_id TEXT,facebook_type TEXT,
facebook_avatar_large TEXT,facebook_avatar_small TEXT,facebook_avatar_local TEXT,
MeetingStatus INTEGER NOT NULL DEFAULT 0);
Code:
CREATE TABLE Reminders (_id INTEGER PRIMARY KEY,event_id INTEGER,minutes INTEGER,method INTEGER NOT NULL DEFAULT 0);
and let's take a look at the data inside
Code:
SELECT * FROM Events WHERE _id=208;
SELECT * FROM Reminders WHERE event_id=208;
for example
Code:
208|PC Sync|com.htc.pcsc|||||1||1||Test1||||1||1304445600000|1304449200000|Europe/Brussels|P3600S|0|0|0|1|1|||||||||1|0|1|1|Outlook|0|||||1|8effd54b-5cd3-451c-8602-2d969f1a84c4|2011-05-03 17:20:36|||||||0
and
Code:
203|208||0
Interesting columns are Events.hasAlarm, Reminders.minutes and Reminders.method.
So recall that I have over 200 calendar entries that had lost their alarms during transfer. How to fix this? Simply
Code:
UPDATE Events SET hasAlarm=1;
UPDATE Reminders SET method=1;
UPDATE Reminders SET minutes=10;
Now put the modified database back to the phone
Code:
adb push calendar.db /data/data/com.android.providers.calendar/databases/calendar.db
and reboot.
And that's it. All alarms are now set properly and work! To attain Nokia-like calendar alerts I'm using application 'Calendar Snooze' and it works like a charm!
Thanks for reading and sorry for being overjoyed but sheer possibility to fix the data in the cellphone by directly accessing it's sql database is so amazing
Maybe for you guys it's not so amazing after all but for someone who just switched from Nokia and found out something like that for the first time it's incredible.
I hope that this post will possibly help someone with similar problem one day
Kind regards,
dominik6
PS.
The possibilities are endless. You can add indices to tables (to maybe speed up some weird searches); add triggers (for example it's easy to do a inside-database backup by using an after insert trigger to duplicate data to another table), one can bulk update/insert/delete entries in calendar, and so on...
PPS.
SMS and contacts are also stored in sqlite databases...

[TUTORIAL] unread mail count tasker all mail clients (imap)

No idea where to put this, admin; feel free to move or delete.
There's a lot of really cool custom theming going on with Android and an often important part of that is the visual indication of missed phone calls, new messages, new mail, etc. (unread bubbles next to app icons, in lockscreens, etc.). There's a host of solutions to get this info but for me e-mail counts had always been a bit of a issue. Missed phone calls are tracked by the Android system, and WhatsApp notifications can be counted from the notification bar with Tasker and reset when you open the app because your phone is the only place where you will check your WhatsApp messages. E-mail however is not centralized in Android (yet) so if you use anything else than Gmail the system won't know how many unread mails you have and you could uee a notification counter on your mail app but when a new email arrives it will put the counter on +1, if you then read the e-mail on another device (for example your computer) your notification counter on your phone will still be on +1 even though you read the mail.You then have to open your mail app to get the counter back to 0 again.
That why I made this PHP / Tasker solution for my IMAP mail. This is a PHP script that checks how many unread mails there are in your inbox:
PHP:
<?php
function mailCount($host, $login, $passwd) {
$mbox = imap_open($host, $login, $passwd);
$mail = '';
if($mail = imap_check($mbox)) {
$msgnos = imap_search($mbox, 'UNSEEN');
return $msgnos;
}
}
$hostname = '{imap.yourhost.com:143/imap}INBOX';
$username = 'your_username';
$password = 'your_password';
$count = mailCount($hostname, $username, $password);
if ($count != "") $number = sizeof($count);
else $number = 0;
echo $number;
Change yourhost, your_username and your_password and the port (143). (if you want to, add some extra security by doing IP or Cookie checks), put the PHP file online on your server. The script will then simply show a number of unread mails in your inbox.
Then you can use Tasker to read this number. Add a tasks (for example CheckMailCount) then add the action Net > HTTP Get. For 'Serverort' fill in the url of your script (http://www.yourserver.com/unreadmail.php) and set the Mime Type to 'text/*'. Then in the same task add an action Variables > Variable Set. Give the variable a Name (for example: %MAILCOUNT) and set it To %HTTPD. This will set the %MAILCOUNT variable to the result of the last http Get request ie. the number of unread mails.
You now have a tasker variable with the actual number of unread mails in your inbox.
I use this on my WidgetLocker lockscreen so I trigger the task on Event > Display > On. I added a third action in the CheckMailCount action to set a Zooper Variable (Plugin > Zooper Widget Pro >Edit > ZW Variable = MAILNOTI, ZW Text = %MAILCOUNT) you could also make this %HTTPD straight away if you don't use the variable for anything else. You then have the #TMAILNOTI# variable in Zooper to use to display how many unread mails you have in a widget. I don't use the count but I display a mail icon indicating that I have a new mail if the #TMAILNOTI# is anything but 0. I do this by adding a bitmap in Zooper of a mail icon and then in Avanced Parameters I put
$#TMAILNOTI#=0?/sdcard/icons/nomail.png$
This tells Zooper that if the variable #TMAILNOTI# = 0 it should use the bitmap nomail.png in my icons folder on the sd card. nomail.png in my case is simply an empty transparent png.
Hope this helps somebody!
nielshtc said:
No idea where to put this, admin; feel free to move or delete.
There's a lot of really cool custom theming going on with Android and an often important part of that is the visual indication of missed phone calls, new messages, new mail, etc. (unread bubbles next to app icons, in lockscreens, etc.). There's a host of solutions to get this info but for me e-mail counts had always been a bit of a issue. Missed phone calls are tracked by the Android system, and WhatsApp notifications can be counted from the notification bar with Tasker and reset when you open the app because your phone is the only place where you will check your WhatsApp messages. E-mail however is not centralized in Android (yet) so if you use anything else than Gmail the system won't know how many unread mails you have and you could uee a notification counter on your mail app but when a new email arrives it will put the counter on +1, if you then read the e-mail on another device (for example your computer) your notification counter on your phone will still be on +1 even though you read the mail.You then have to open your mail app to get the counter back to 0 again.
That why I made this PHP / Tasker solution for my IMAP mail. This is a PHP script that checks how many unread mails there are in your inbox:
PHP:
<?php
function mailCount($host, $login, $passwd) {
$mbox = imap_open($host, $login, $passwd);
$mail = '';
if($mail = imap_check($mbox)) {
$msgnos = imap_search($mbox, 'UNSEEN');
return $msgnos;
}
}
$hostname = '{imap.yourhost.com:143/imap}INBOX';
$username = 'your_username';
$password = 'your_password';
$count = mailCount($hostname, $username, $password);
if ($count != "") $number = sizeof($count);
else $number = 0;
echo $number;
Change yourhost, your_username and your_password and the port (143). (if you want to, add some extra security by doing IP or Cookie checks), put the PHP file online on your server. The script will then simply show a number of unread mails in your inbox.
Then you can use Tasker to read this number. Add a tasks (for example CheckMailCount) then add the action Net > HTTP Get. For 'Serverort' fill in the url of your script (http://www.yourserver.com/unreadmail.php) and set the Mime Type to 'text/*'. Then in the same task add an action Variables > Variable Set. Give the variable a Name (for example: %MAILCOUNT) and set it To %HTTPD. This will set the %MAILCOUNT variable to the result of the last http Get request ie. the number of unread mails.
You now have a tasker variable with the actual number of unread mails in your inbox.
I use this on my WidgetLocker lockscreen so I trigger the task on Event > Display > On. I added a third action in the CheckMailCount action to set a Zooper Variable (Plugin > Zooper Widget Pro >Edit > ZW Variable = MAILNOTI, ZW Text = %MAILCOUNT) you could also make this %HTTPD straight away if you don't use the variable for anything else. You then have the #TMAILNOTI# variable in Zooper to use to display how many unread mails you have in a widget. I don't use the count but I display a mail icon indicating that I have a new mail if the #TMAILNOTI# is anything but 0. I do this by adding a bitmap in Zooper of a mail icon and then in Avanced Parameters I put
$#TMAILNOTI#=0?/sdcard/icons/nomail.png$
This tells Zooper that if the variable #TMAILNOTI# = 0 it should use the bitmap nomail.png in my icons folder on the sd card. nomail.png in my case is simply an empty transparent png.
Hope this helps somebody!
Click to expand...
Click to collapse
This looks way to confusing but I get it a little bit... lets say I want to use UCCW tasker variable option to show the counts...:silly:

[Q] How do retrieve video and audio from whatsapp db

I write little application for design message history from whatsapp app. The whatsapp app is stored data into sqlite db.
First of all I decrypt the db.
Secondly, I see that the DB have a table for messages, with those columns:
Code:
TABLE messages
(
_id INTEGER PRIMARY KEY AUTOINCREMENT,
key_remote_jid TEXT NOT NULL,
key_from_me INTEGER,
key_id TEXT NOT NULL,
status INTEGER,
needs_push INTEGER,
data TEXT,
timestamp INTEGER,
media_url TEXT,
media_mime_type TEXT,
media_wa_type TEXT,
media_size INTEGER,
media_name TEXT,
media_hash TEXT,
media_duration INTEGER,
origin INTEGER,
latitude REAL,
longitude REAL,
thumb_image TEXT,
remote_resource TEXT,
received_timestamp INTEGER,
send_timestamp INTEGER,
receipt_server_timestamp INTEGER,
receipt_device_timestamp INTEGER,
raw_data BLOB,
recipient_count INTEGER
)
So, there have a records for images, video, audio and etc. (they are stored on raw_data column)
Now, for every record I try to save to local directory on my pc, as follows:
First way:
Code:
File.WriteAllBytes(Path.Combine(directoryPath, msg.Media.MediaName)), msg.Media.RAW_DATA);
But I see, that it working only for image files, not for audio and video files..
Second way:
Code:
using (FileStream fs = new FileStream(Path.Combine(directoryPath, msg.Media.MediaName), FileMode.Create))
{
using (BinaryWriter writer = new BinaryWriter(fs))
{
writer.Write(msg.Media.RAW_DATA);
}
}
but I get same results
the audio and the video are not stored on the db?
Anybody?
Sent from my HTC One using XDA Premium 4 mobile app
I think that nobody knows the answer:\

[Q] App to read NFC codes and write them to a text file

Hi guys,
I'm looking for an android app to read the value of an NFC chip and write that value to a text file.
What I'm looking for is basically the same functionality as when you would hook up an USB NFC-reader to a PC, and write the scanned values to a notepad file.
The situation in which this would be used is to scan people entering a training session on a company event.
Attendees would have an NFC-enabled name tag, and we have a list of nfc-values to correspond to the attendees already stored in the database.
Do you guys know of any apps that could provide this functionality?

[Q] Automagic Automation. Read strings file to array

ping adresses from file, send sms report to adresses by list
Google translator:
Guys, prompt, really I create a variable named stream?
I want the next copy flow and rename it to a variable was created and written with the new name of the stream. {Flow_name} understandable. But how to create a recess with the same name?
For example. I want to ping the IP pieces 20. Every minute to write the log of the results. Then, when the state variable and the status of the ping, disappeared so to speak, I will send a sms with the text of the ping and the IP address.
Can anyone implemented such a thing?
Or please tell me how to file a list of IP by turns to take each line and ping this address.
Write to a file ravine easy. Understood.
By ftp or something else is taken from time to time files:
1. hosts
2. phonenumbers
3. log
Taken one by one the IP address of the hosts file and ping.
(Host reacheble ping)
Is compared with the current state of the Previous and the difference is sent SMS.
SMS is formed on the result of the passage of all addresses. Infa accumulates and then sent.
"/ N" works as a new line? printed only as text and everything. Maybe the code should be some kind?
Just please tell me the procedure (code) to read a line from a file and writes to the array a. On the arduino can do, and then what?
There is a file: hosts. it placed the IP address line (20 pieces, strings).
Pinging each address one time per minute.
Compare the current state of the IP address (192.168.0.1) to the last variable ("192.168.0.1").
If different, write to another variable "TEXTtoSMS": IP address, date, time, current status.
Write to the variable ("192.168.0.1") the current status of the address.
And so for each IP address of the file.
When all the rows have been (address) check for the presence of text in the variable "TEXTtoSMS" and send SMS to the addresses that I take from another file.
Do I need to somehow individually declare a variable? Or enough (stat_19216801 = "on")? I want to create a variable named stream. {Flow_name}. Really it?
Or it is necessary to enclose an array of two columns? The first IP address, the second status. After checking the status of an IP address, run the array. Looking in the first column of our address and check the option recorded in the second column. How do I proceed with the formation of protsedurka "TEXTtoSMS" ..
How to add a translation to a new line when writing text into a variable "TEXTtoSMS"?
for example
files:
1. hosts:
192.168.0.1
192.168.0.2
......
.
.
..
2. calls:
+7********
+7********
+7********
3. log:
ip adress, date, time, status (online, ofline)
1. need to read from file HOSTS, ip adress from line1 and ping. Or get all lines from file HOSTS to array with 2 columns. Frist column for ip adress, second column for previous status (online, ofline).
For each ip need ping then compare now status with previous status.
If status changed, add to value "TEXTtoSMS" (ip, status). At the end of string add "/n", for insert code NEXT STRING (like in Arduino "Println(text)").
Please give me code (example) for read strings from file. Line1, Line2, Line3.
Or get strings from file to array.
I need just it. Next steps not strong for me.

Categories

Resources