Note that there are some explanatory texts on larger screens.

plurals
  1. POupdating sqlite in android
    primarykey
    data
    text
    <p>sir, i have a problem in updating my database. i've made a listview containing this data</p> <pre><code>name phone number status </code></pre> <p>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</p> <pre><code>name phone number available </code></pre> <p>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</p> <pre><code>09211234567 </code></pre> <p>the sender will return their phone number as </p> <pre><code>+639211234567 </code></pre> <p>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".</p> <p>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. </p> <p>i saved the number of emulator in my listview as </p> <pre><code>5556 </code></pre> <p>but the emulator returns </p> <pre><code>15555215556 </code></pre> <p>so i just get the substring to get 5556</p> <p>please help me. here is my code:</p> <pre><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&lt;pdusObj.length; i++) { messages[i] = SmsMessage.createFromPdu ((byte[]) pdusObj[i]); sender = messages[i].getOriginatingAddress(); } for (SmsMessage msg : messages) { if (msg.getMessageBody().contains("available")) { info.open(); String remFirstChar = sender.substring(3); addNum += remFirstChar; Toast.makeText(context.getApplicationContext(), "received sms from: " +addNum, Toast.LENGTH_LONG).show(); //if starts with +639 if(sender.length() == 13) { info.updateStatus(addNum, aStatus); Toast.makeText(context.getApplicationContext(), "addNum: " +addNum, Toast.LENGTH_LONG).show(); } else { Toast.makeText(context.getApplicationContext(), "sender: " +sender, Toast.LENGTH_LONG).show(); info.updateStatus(remFirstChar, aStatus); } info.close(); }//end if - available </code></pre> <p>here is how i updated my status</p> <pre><code>//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); } </code></pre> <p>update: 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.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload