2011-09-07 125 views
1

我正在写一个应用程序发送短信(与SmsManager),并且我想知道消息是否已成功发送。我打算使用ContentObserver与content://sms/sent,但可能不是一个好主意,因为我只想处理由我的应用程序发送的消息。短信发送ContentObserver

有什么建议吗?

回答

2

使用此代码,可以帮助你....

public void onReceive(Context arg0, Intent arg1) {     
    switch (getResultCode()) {      
     case Activity.RESULT_OK: 
      //message sent 
      break; 

     case SmsManager.RESULT_ERROR_GENERIC_FAILURE:       
      Toast.makeText(getBaseContext(), "Generic failure",         
      Toast.LENGTH_SHORT).show();       
      break;      

     case SmsManager.RESULT_ERROR_NO_SERVICE:       
      Toast.makeText(getBaseContext(), "No service",         
      Toast.LENGTH_SHORT).show();       
      break;      

     case SmsManager.RESULT_ERROR_NULL_PDU:       
      Toast.makeText(getBaseContext(), "Null PDU",         
      Toast.LENGTH_SHORT).show();       
      break;      

     case SmsManager.RESULT_ERROR_RADIO_OFF:       
      Toast.makeText(getBaseContext(), "Radio off",         
      Toast.LENGTH_SHORT).show();       
      break; 

    }  
} 
+0

我必须把'registerReceiver)代码(新的广播接收器({}'? – supergiox

+0

是......你把代码广播registerreceiver – Siva

+0

谢谢!它的作品:) – supergiox