Thursday, August 14, 2014

2.3 gingerbread - Transferring messages to android from a sqlite db on my laptop


I am a new android user. I switched from nokia to android today only. Been googling around for various solutions to transfer my sms (text messages only) from my old nokia to my new Android (Galaxy Ace with Android 2.3).


After exploring my laptop, I found the synced(using Nokia PC Suite) sms were stored in AppData as a sqlite file.


Can I transfer all these to my new Android? Any app for this?



Answer



Well I solved the problem. Documenting the solution here for future references.


Using any sqlite manager (I used firefox plugin- SQlite Manager), export the database to XML format (generally any db manager has options to export the database in csv, xls & xml formats).


If your sqlite was generated by nokia pc-suite sync, you would get an xml like:











Your message body
+919203487229
1
1305483332
355940045825435
36
{c33eb602-1456-4542-a755-268dc3728638}

4487229


0


0


Hi gopi, how are you? ;)

+919582821300
1
1305516490
355940045825435
36
{15a0d257-2318-4baa-b764-dd14c1aa1fb5}
2821300


0



0




Then you can use the following php script to do the conversion to the generate the xml format script required by the SMS Backup and Restore App.




$file=fopen("sms-20120708160401.xml", "w");
$xml=simplexml_load_file("messages.xml");
echo $xml->getName()."

";
$begin="\n";
$begin.=''."\n";
$begin.=''."\n";
fwrite($file,$begin);
$start=' $finish='/>';
$i=1;

$j=0;

foreach($xml->children()->children() as $table) {
echo $i++." ";
$read=1;
$msg_status=$table->column[5];
$msg_folder=$table->column[2];
if($msg_status=="34") {
$type=1;
$read=0;

}
else if($msg_status=="36") {
if($msg_folder=="4294967295") {
$type=3;
}
else {
$type=1;
}
}
else if($msg_status=="1" || $msg_status=="5") {

if($msg_folder=="4294967295") {
$type=3;
}
else {
$type=2;
}
}
else {
echo "
".$msg_status."; ".$msg_folder."

";
}

$body=htmlspecialchars($table->column[0]);
$body=str_replace("\n", ' ', $body);
$address=$table->column[1];
if(strlen($address)==11) {
$address="+91".substr($address,1);
}
else if(strlen($address)==10) {
$address="+91".$address;
}
else if($address=="") {

$i--;
continue;
}

$sms=$start;
$sms.='address="'.$address.'" ';
$sms.='date="'.$table->column[3].'000" ';
$sms.='type="'.$type.'" ';
$sms.='subject="null" ';
$sms.='body="'.$body.'" ';

$sms.='toa="null" ';
$sms.='sc_toa="null" ';
$sms.='service_center="null" ';
$sms.='read="'.$read.'" ';
$sms.='status="-1" ';
$sms.='locked="0" ';
$sms.='date_sent="null" ';
$sms.=$finish."\n";

fwrite($file, $sms);

}

$end='
';
fwrite($file, $end);
fclose($file);

?>

One point to be noted:


You have to manually write the count attribute in the smses tag. Just check the number of lines in your generated xml file & subtract 4 from it OR just write the last echoed integer by the script



Now just send this to your android & restore using the SMS Backup & Restore App. Bingo! you are done!


No comments:

Post a Comment

samsung galaxy s 2 - Cannot restore Kies backup after firmware upgrade

I backed up my Samsung Galaxy S2 on Kies before updating to Ice Cream Sandwich. After the upgrade I tried to restore, but the restore fails ...