2013-08-23 91 views

回答

0

你實際上需要在發送前一之前發送下一個短信,爲此,你需要檢查發送短信的狀態,請參閱本教程,它說:

如果你需要監視的狀態在短信發送過程中,你其實可以使用兩個的PendingIntent有兩個廣播接收器對象組合在一起的對象,像這樣:

//---sends an SMS message to another device--- 
    private void sendSMS(String phoneNumber, String message) 
    {   
     String SENT = "SMS_SENT"; 
     String DELIVERED = "SMS_DELIVERED"; 

     PendingIntent sentPI = PendingIntent.getBroadcast(this, 0, 
      new Intent(SENT), 0); 

     PendingIntent deliveredPI = PendingIntent.getBroadcast(this, 0, 
      new Intent(DELIVERED), 0); 

     //---when the SMS has been sent--- 
     registerReceiver(new BroadcastReceiver(){ 
      @Override 
      public void onReceive(Context arg0, Intent arg1) { 
       switch (getResultCode()) 
       { 
        case Activity.RESULT_OK: 
         Toast.makeText(getBaseContext(), "SMS sent", 
           Toast.LENGTH_SHORT).show(); 
         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; 
       } 
      } 
     }, new IntentFilter(SENT)); 

     //---when the SMS has been delivered--- 
     registerReceiver(new BroadcastReceiver(){ 
      @Override 
      public void onReceive(Context arg0, Intent arg1) { 
       switch (getResultCode()) 
       { 
        case Activity.RESULT_OK: 
         Toast.makeText(getBaseContext(), "SMS delivered", 
           Toast.LENGTH_SHORT).show(); 
         break; 
        case Activity.RESULT_CANCELED: 
         Toast.makeText(getBaseContext(), "SMS not delivered", 
           Toast.LENGTH_SHORT).show(); 
         break;       
       } 
      } 
     }, new IntentFilter(DELIVERED));   

     SmsManager sms = SmsManager.getDefault(); 
     sms.sendTextMessage(phoneNumber, null, message, sentPI, deliveredPI);   
    } 
+0

thankx的答案,但它不是我要求我必須通過點對點無線網絡發送直接連接 – Priyanka

+0

請幫我,我沒有任何想法如何做到這一點。 – Priyanka

+0

嘗試這個鏈接,這可能會幫助你http://code.google.com/p/sip2peer/ –

相關問題