0

我正在尝试编写自己的短信管理器,并且发现了许多教程如何使用 URI 和光标获取短信和彩信,但每次尝试我都会遇到无法解决的问题。希望你能帮我一点忙。好的,所以我一直在使用“content://mms-sms/conversations/”,它应该适用于 SMS 和 MMS。当然不是。这段代码:

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( ) ) );

返回 13这是 false,因为当我打开我的标准 android 邮箱时,我统计了 18 个对话。

第二件事,也试图从对话中获取“地址”:

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" ) ) ); 

有时地址是数字,有时是名称,有时为空。为什么?我怎样才能解决这个问题?

第三件事,在许多教程中,在 stackoverflow 中,也有非常简单的解决方案如何从 MMS 获取地址。只需从 MMS 获取 cursor.getString(cursor.getColumnIndexOrThrow("address")) 并完成。HTC 没有。我试过这个:

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 ) ); 
}

它还给了我:

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

所以这意味着我在彩信中没有字段“地址”。那么如何获取地址呢?我只能得到线程,但一半的谈话是看不见的。看来编写自己的 SMS/MMS 管理器是不可能的,HTC 的 bug 太多了。

Google Play 上有一个名为“GO SMS Pro”的应用程序,它在我的手机上运行良好。所以这意味着有一种方法可以正确编码。我做错了什么?如何修复它并正确获取 SMS 和 MMS?

4

2 回答 2

0

从“内容://mms-sms/conversations/”更改为“内容://mms-sms/conversations”

于 2013-08-13T12:21:50.517 回答
0

尝试

Uri    uri    = Uri.parse("content://mms-sms/conversations?simple=true");
于 2016-04-13T09:13:08.533 回答