我想寫我自己的短信管理器,我發現很多教程如何獲取帶有URI和光標的短信和彩信,但每次嘗試我都會遇到問題,我可以不解決。希望你能幫我一下。 好吧,所以我一直在使用「content:// mms-sms/conversations /」,它既適用於SMS又適用於MMS。當然不是。此代碼:試圖在Android上獲取短信和彩信 - HTC問題
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 哪個是假的,因爲當我打開我的標準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
因此,這意味着我必須在MMS NO場 「地址」。那麼我怎樣才能得到地址?我只能得到線索,但一半的談話是隱形的。它看起來是不可能編碼自己的SMS/MMS管理器,HTC上有這麼多的錯誤。
在Google Play上有一個名爲「GO SMS Pro」的應用程序,可以在我的手機上正常工作。所以這意味着有一種方法可以正確編碼。我做錯了什麼?我如何解決這個問題並獲得正確的SMS和MMS?