Search code examples
androidmms

MMS sender address problem


I am trying to get the address of the sender but I run into a little problem. If the person that sends the message is the first person in any of the conversations to send one, the query of the content://mms/inbox returns with zero rows?? but when someone sends any other mms message it will return back with the _id fine and i dont understand why the first one wont work right?

private String checkMmsMessages(Context context){
    String address = "address";

    Cursor curPdu = context.getContentResolver ().query(Uri.parse("content://mms/inbox"), null, null, null, null);
    if(curPdu.moveToNext()){ //first MMS message curPdu.moveToNext() is false
    String id = curPdu.getString (curPdu.getColumnIndex ("_id"));

    Log.v("MMS", "ID1: " + id.toString());

    Uri uriAddr = Uri.parse ("content://mms/" + id + "/addr");
    Cursor curAddr = context.getContentResolver().query(uriAddr,null,"type=137",null,null);
    if(curAddr.moveToNext()){
             address = curAddr.getString (curAddr.getColumnIndex ("address"));
             Log.v("MMS", "Address1: " + address.toString());
             if(address.contentEquals("insert-address-token")){
                 Cursor curAddr2 = context.getContentResolver().query(uriAddr,null,"type=151", null,null);
                 if(curAddr2.moveToNext()){
                     address = curAddr2.getString(curAddr2.getColumnIndex("address"));
                 }
             }
        }
    }
    Log.v("MMS", address.toString());
    return address;
}

Also something else that does not make sense is when when i have the phone plugged into the computer and step through the that section with the debugger, that problem does not happen and it gets the address every time.... it only happens when the phone is not connected, i just dont understand?


Solution

  • The problem was I was checking the database before the message was put into the database so I had to put a delay on the check