2

How can I compare a phone number from the getOriginatingAddress() to my custom contact listview? i want to change the status to "available" but it doesn't update my listview and still shows the default "not available". is it possible to use the ourDatabase.update() if what i am using as a condition which is "KEY_NUMBER = mNumber" is not a primary key? thanks for help in advance

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

Here is how i get the phone number of sender

public String aStatus = "available";
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[]) 
            pdusObj[i]); 
            sender = messages[i].getOriginatingAddress();
    } 

    for (SmsMessage msg : messages) {
        if (msg.getMessageBody().contains("available")) {
            info.open();
            Toast.makeText(context.getApplicationContext(), "received sms from: " +sender,
                Toast.LENGTH_SHORT).show();

            info.updateStatusAvailable(sender);

            info.close();
        }//end if - available

        if(msg.getMessageBody().contains("notavailable")) 
        {


        }//end if - not available
    }//end for

}// end onreceive

another thing i am concerned about is my contact list, if i entered the number as "09211234567", the originating address may return "+639211234567". i've tried it in an emulator and send it to the address "5556" but the getOriginatingAddress() returned something like "15555215556". how do i deal with that?

David Snabel-Caunt
  • 57,804
  • 13
  • 114
  • 132
Usui Takumi
  • 355
  • 2
  • 5
  • 19

1 Answers1

1

You have to refresh your list view. That's because the list view, once displayed, will not refresh automaticaly.

You can do it after the update done on the database.

In order to refresh your listview, see: How to refresh Android listview?

Community
  • 1
  • 1
Milos Cuculovic
  • 19,631
  • 51
  • 159
  • 265
  • so, i should refresh it after this line? info.updateStatusAvailable(sender); – Usui Takumi Nov 28 '12 at 11:38
  • Yes, to refresh the data, please see here http://stackoverflow.com/questions/2250770/how-to-refresh-android-listview – Milos Cuculovic Nov 28 '12 at 11:53
  • thanks, but i'm also concerned with the other thing, i've tried it in an emulator and send it to the address "5556" but the getOriginatingAddress() returned something like "15555215556". how do i deal with that? – Usui Takumi Nov 28 '12 at 12:22
  • You are welcome. Please confirm my response for this question and ask a new one for the second problem. Those two things are completely separated and it is mandatory to distingush them in two separate questions. Thank you. – Milos Cuculovic Nov 28 '12 at 12:31
  • No problem, You can post a second question. – Milos Cuculovic Nov 28 '12 at 12:42