2011-09-07 65 views

回答

2

您可以獲取發送消息:

Uri mSmsinboxQueryUri = Uri.parse("content://sms/sent"); 
    Cursor cursor1 = getContentResolver().query(mSmsinboxQueryUri, 
       new String[] { "_id", "thread_id", "address", "person", "date", 
           "body", "type" }, null, null, null); 
    startManagingCursor(cursor1); 
    String[] columns = new String[] { "address", "person", "date", "body","type" }; 
    if (cursor1.getCount() > 0) { 
     String count = Integer.toString(cursor1.getCount()); 
     Log.e("Count",count); 
     while (cursor1.moveToNext()){ 
      String address = cursor1.getString(cursor1.getColumnIndex(columns[0])); 
      String name = cursor1.getString(cursor1.getColumnIndex(columns[1])); 
      String date = cursor1.getString(cursor1.getColumnIndex(columns[2])); 
      String msg = cursor1.getString(cursor1.getColumnIndex(columns[3])); 
      String type = cursor1.getString(cursor1.getColumnIndex(columns[4])); 
     } 
    } 

可以使用計數器以檢索最近發來的短信。

請參閱其他有用的鏈接:

Android: Is there any way to listen outgoing sms?

Listen outgoing SMS or sent box in Android

How to listen/subscribe to Outgoing SMS notifications?

+0

出於某種原因內容://短信/ SENT不適合我,但工作內容://短信/做。你爲什麼認爲這是事實? – gonzobrains

-2

使用的服務。向通過braodcastreceiver發送短信時接收消息的服務註冊一個監聽器。

使用該清單中

<receiver android:name="SmsReceiver"> 
     <intent-filter> 
      <action android:name= 
       "android.provider.Telephony.SMS_RECEIVED" /> 
     </intent-filter> 
    </receiver> 

代碼smsreceiver

public class SmsReceiver extends BroadcastReceiver 

{ 

    @Override 

    public void onReceive(Context context, Intent intent) 

    { 

     //here your code 



    } 



} 
+1

這適用於*傳入*文本消息,但OP正在詢問*傳出*文本。目前,沒有廣播接收傳出文本。 – Jag

相關問題