updating sqlite using where clause

  • Replies:0
  • OpenNot stickiedUnanswered

Dec 3, 2012 10:51:39 PM via Website

sir, i have a problem in updating my database. i've made a listview containing this data

phone number

i would like to update the status of person if he sent a message with a keyword "available" in it and would update my listview like this

phone number

so i decided to make the phone number as the trigger. if the phone number of the person who sent the message is in my listview, it will update the database. but here is my problem, if i saved the phone number in my listview in this format


the sender will return their phone number as


so i worked around this by getting the substring and cut the phone number into "9211234567", and then add 0 to transform it into "09211234567".

however, the database status still doesn't update. but when i used the same technique in sending sms from emulator to emulator, it works just fine.

i saved the number of emulator in my listview as


but the emulator returns


so i just get the substring to get 5556

please help me. here is my code:

public static String sender;
public GroupDb info;
public String aStatus = "available";
public String nStatus = "not available";
public String addNum = "0";
public void onReceive(Context context, Intent intent) {
// TODO Auto-generated method stub
info = new GroupDb(context);
Bundle bundle = intent.getExtras();
Object[] pdusObj = (Object[]) bundle.get("pdus");
SmsMessage[] messages = new SmsMessage[pdusObj.length];
for (int i = 0; i<pdusObj.length; i++)
messages[i] = SmsMessage.createFromPdu ((byte[])
sender = messages[i].getOriginatingAddress();

for (SmsMessage msg : messages) {
if (msg.getMessageBody().contains("available")) {

String remFirstChar = sender.substring(3);
addNum += remFirstChar;
Toast.makeText(context.getApplicationContext(), "received sms from: " +addNum,
//if starts with +639
if(sender.length() == 13)
info.updateStatus(addNum, aStatus);
Toast.makeText(context.getApplicationContext(), "addNum: " +addNum,
Toast.makeText(context.getApplicationContext(), "sender: " +sender,
info.updateStatus(remFirstChar, aStatus);
}//end if - available

here is how i updated my status

//update status
public void updateStatus(String mNumber, String mStatus) throws SQLException
// TODO Auto-generated method stub
ContentValues cvUpdate = new ContentValues();
cvUpdate.put(KEY_STATUS, mStatus);
ourDatabase.update(DATABASE_TABLE, cvUpdate, KEY_NUMBER + "=" + mNumber, null);

i even tried to enter "+63" format in listview but still, i won't update. all functions such as deletion and editing also don't work and shows force close.