2011-08-19 59 views
0

如何將短信發送到多個聯繫人,並獲得android中的每個人的結果代碼?如何發送短信給多個聯繫人,並獲得他們每個人的結果代碼在android123

我問下面的鏈接了同樣的問題,但無法找到一個解決方案:

+0

我會說你所尋求的知識不在這裏 - 另一個地方可能是另一個地方owledge sink – KevinDTimm

+0

你到現在爲止所嘗試過的。 –

+0

Downvoting,因爲這不是一個問題,你顯然試圖通過垃圾郵件濫用SO的工作方式。 – Layke

回答

0

這可能會幫助你

private void sendSMS(final String phoneNumber, String message,String messageID) 
{   
    PendingIntent pi = PendingIntent.getActivity(this, 0, 
     new Intent(this, SM.class), 0);  
    pi.putExtras("messageID",messageID);    
    SmsManager sms = SmsManager.getDefault(); 
    //sms.sendTextMessage(phoneNumber, null, message, pi, null); 


    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); 
    sms.sendTextMessage(phoneNumber, null, message, sentPI, deliveredPI); 


    //---when the SMS has been sent--- 
    registerReceiver(new BroadcastReceiver(){ 
     @Override 
     public void onReceive(Context arg0, Intent arg1) { 
      //showMessage("sms has been sent with reusltcode "+getResultCode()); 
      String id=arg1.getBundle().getExtras().getString("messageID"); 
      //This will recognize your message 

      switch (getResultCode()) 
      { 
       case Activity.RESULT_OK: 
        Toast.makeText(getBaseContext(), "SMS sent to "+phoneNumber, 
          Toast.LENGTH_LONG).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(){ 
     public void onReceive(Context arg0, Intent arg1) { 
      showMessage("sms has been delivered with reusltcode "+getResultCode()); 

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

} 
+0

感謝您的幫助,但pendingintent沒有采取額外的措施 – Sando

+0

PendingIntent pi = PendingIntent.getActivity(this,0,012,new Intent(this,SM.class),0); pi.putExtras(「messageID」,messageID); – Sando

+0

嘗試使用請求代碼。第2個參數是請求代碼。爲每個消息更改此參數並實現onActivityResult並檢索請求代碼 – Rasel

相關問題