0

I'm trying to write my own SMS manager and I found many tutorials how to get SMS and MMS with URI and Cursor, but each try I'm getting problems I can't solve. Hope you help me a bit. Okay, so I've been using "content://mms-sms/conversations/" which should work both for SMS and MMS. Of course not. This code:

final String[ ] projection = new String[ ]{ "*" };
Uri uri = Uri.parse( "content://mms-sms/conversations/" );
Cursor query = getContentResolver( ).query( uri, projection, null, null, null );

TextView text = ( TextView )findViewById( R.id.textView1 );
text.setText( Integer.toString( query.getCount( ) ) );

Return 13 which is false, because when I opened my standard android mailbox, I counted 18 conversations.

Second thing, also tried to get "address" from conversations:

final String[] projection = new String[]{"*"};
Uri uri = Uri.parse("content://mms-sms/conversations/");
Cursor query = getContentResolver( ).query(uri, projection, null, null, null);
while( query.moveToNext( ) )
    System.out.println( "recv " + query.getString( query.getColumnIndexOrThrow( "address" ) ) ); 

Sometimes the address is a number, sometimes is a name, and sometimes is null. Why? How can I fix this?

Third thing, on many tutorials, in stackoverflow too, there is very simple solution how to get addresss from MMS. Just get cursor.getString( cursor.getColumnIndexOrThrow( "address" ) ) from MMS and done. Not here on HTC. I tried this:

Cursor cursor = getContentResolver( ).query( Uri.parse( "content://sms/inbox" ), null, null, null, null );
if( cursor.moveToFirst( ) ) 
{
    for( int i = 0; i < cursor.getColumnCount( ); i++ ) 
        System.out.println( "SMS " + cursor.getColumnName( i ) ); 
}

for( int i = 0; i < 3; i++ )
        System.out.println( "***************************************************************" ); 

Cursor cursor2 = getContentResolver( ).query( Uri.parse( "content://mms/inbox" ), null, null, null, null );
if( cursor2.moveToFirst( ) ) 
{
    for( int i = 0; i < cursor2.getColumnCount( ); i++ ) 
        System.out.println( "MMS " + cursor2.getColumnName( i ) ); 
}

And it returned me:

07-21 02:12:40.631: I/System.out(25221): SMS _id
07-21 02:12:40.631: I/System.out(25221): SMS thread_id
07-21 02:12:40.631: I/System.out(25221): SMS toa
07-21 02:12:40.631: I/System.out(25221): SMS address
07-21 02:12:40.631: I/System.out(25221): SMS person
07-21 02:12:40.631: I/System.out(25221): SMS date
07-21 02:12:40.631: I/System.out(25221): SMS protocol
07-21 02:12:40.631: I/System.out(25221): SMS read
07-21 02:12:40.631: I/System.out(25221): SMS status
07-21 02:12:40.631: I/System.out(25221): SMS type
07-21 02:12:40.631: I/System.out(25221): SMS reply_path_present
07-21 02:12:40.631: I/System.out(25221): SMS subject
07-21 02:12:40.631: I/System.out(25221): SMS body
07-21 02:12:40.631: I/System.out(25221): SMS sc_toa
07-21 02:12:40.631: I/System.out(25221): SMS report_date
07-21 02:12:40.631: I/System.out(25221): SMS service_center
07-21 02:12:40.631: I/System.out(25221): SMS locked
07-21 02:12:40.631: I/System.out(25221): SMS index_on_sim
07-21 02:12:40.631: I/System.out(25221): SMS callback_number
07-21 02:12:40.631: I/System.out(25221): SMS priority
07-21 02:12:40.631: I/System.out(25221): SMS htc_category
07-21 02:12:40.631: I/System.out(25221): SMS cs_timestamp
07-21 02:12:40.631: I/System.out(25221): SMS cs_id
07-21 02:12:40.631: I/System.out(25221): SMS cs_synced
07-21 02:12:40.631: I/System.out(25221): SMS error_code
07-21 02:12:40.631: I/System.out(25221): SMS seen
07-21 02:12:40.641: I/System.out(25221): SMS is_cdma_format
07-21 02:12:40.641: I/System.out(25221): SMS is_evdo
07-21 02:12:40.641: I/System.out(25221): SMS c_type
07-21 02:12:40.641: I/System.out(25221): SMS exp
07-21 02:12:40.641: I/System.out(25221): SMS gid
07-21 02:12:40.641: I/System.out(25221): SMS extra
07-21 02:12:40.641: I/System.out(25221): SMS date2
07-21 02:12:40.641: I/System.out(25221): 
***************************************************************
07-21 02:12:40.641: I/System.out(25221): 
***************************************************************
07-21 02:12:40.641: I/System.out(25221): 
***************************************************************
07-21 02:12:40.691: I/System.out(25221): MMS _id
07-21 02:12:40.691: I/System.out(25221): MMS thread_id
07-21 02:12:40.691: I/System.out(25221): MMS date
07-21 02:12:40.691: I/System.out(25221): MMS msg_box
07-21 02:12:40.691: I/System.out(25221): MMS read
07-21 02:12:40.691: I/System.out(25221): MMS m_id
07-21 02:12:40.691: I/System.out(25221): MMS sub
07-21 02:12:40.691: I/System.out(25221): MMS sub_cs
07-21 02:12:40.691: I/System.out(25221): MMS ct_t
07-21 02:12:40.691: I/System.out(25221): MMS ct_l
07-21 02:12:40.691: I/System.out(25221): MMS exp
07-21 02:12:40.691: I/System.out(25221): MMS m_cls
07-21 02:12:40.691: I/System.out(25221): MMS m_type
07-21 02:12:40.691: I/System.out(25221): MMS v
07-21 02:12:40.691: I/System.out(25221): MMS m_size
07-21 02:12:40.691: I/System.out(25221): MMS pri
07-21 02:12:40.691: I/System.out(25221): MMS rr
07-21 02:12:40.691: I/System.out(25221): MMS rpt_a
07-21 02:12:40.691: I/System.out(25221): MMS resp_st
07-21 02:12:40.691: I/System.out(25221): MMS st
07-21 02:12:40.691: I/System.out(25221): MMS tr_id
07-21 02:12:40.691: I/System.out(25221): MMS retr_st
07-21 02:12:40.691: I/System.out(25221): MMS retr_txt
07-21 02:12:40.691: I/System.out(25221): MMS retr_txt_cs
07-21 02:12:40.691: I/System.out(25221): MMS read_status
07-21 02:12:40.691: I/System.out(25221): MMS ct_cls
07-21 02:12:40.691: I/System.out(25221): MMS resp_txt
07-21 02:12:40.691: I/System.out(25221): MMS d_tm
07-21 02:12:40.691: I/System.out(25221): MMS d_rpt
07-21 02:12:40.691: I/System.out(25221): MMS locked
07-21 02:12:40.691: I/System.out(25221): MMS htc_category
07-21 02:12:40.691: I/System.out(25221): MMS cs_timestamp
07-21 02:12:40.691: I/System.out(25221): MMS cs_id
07-21 02:12:40.691: I/System.out(25221): MMS cs_synced
07-21 02:12:40.691: I/System.out(25221): MMS seen
07-21 02:12:40.691: I/System.out(25221): MMS extra
07-21 02:12:40.691: I/System.out(25221): MMS phone_type
07-21 02:12:40.691: I/System.out(25221): MMS date2

So it means I have NO field "address" in MMS. So how can I get the address? I can only get thread, but half of conversation is invisible. It looks like it's impossible to code own SMS/MMS manager, there are so many bugs on the HTC.

There is an app on Google Play named "GO SMS Pro" which works fine on my phone. So it means there IS a way to code it properly. What do I do wrong? How can I fix it and get properly SMSes and MMSes?

exploitr
  • 843
  • 1
  • 14
  • 27

2 Answers2

0

Change from "content://mms-sms/conversations/" to "content://mms-sms/conversations"

0

Try

Uri    uri    = Uri.parse("content://mms-sms/conversations?simple=true");
Sỹ Phạm
  • 530
  • 6
  • 16