2014-09-01 2 views
-1

안녕하세요 다른 텍스트 본문과 다른 휴대폰 번호로 SMS를 보내려고 노력하고 있습니다, 내 코드는 또한 160 문자 이상의 SMS를 보내고 있지만 모두에게 하나의 번호로 보냅니다, 지금하고 싶습니다 모든 연락처 list.pls이안드로이드 SMS가 160 자 이상

개인 무효 sendSMS()

{ 
     if (list_phone.size()!=0){ 

      //new AddNewCategory().execute(); 
      for (i = 0; i < len; i++){ 


     SmsManager sm = SmsManager.getDefault(); 
     ArrayList<String> message_parts = sm.divideMessage(list_MESSAGE_BODY.get(i)); 

     // Log.e("Message parts 3", message_parts.get(3)); 
     // Log.e("Message parts 4", message_parts.get(4)); 
     Intent iSent = new Intent(); 
     PendingIntent piSent = PendingIntent.getBroadcast(this, 0, iSent, 0); 
     Intent iDel = new Intent(); 
     PendingIntent piDel = PendingIntent.getBroadcast(this, 0, iDel, 0); 

     if (message_parts.size() == 1) 
     { 
      String msg = message_parts.get(0); 
      sm.sendTextMessage(list_phone.get(i), null, msg, piSent, piDel); 
      Toast.makeText(getApplicationContext(), " Message sent", Toast.LENGTH_SHORT).show(); 

     } 
     else 
     { 
      ArrayList<PendingIntent> sentPis = new ArrayList<PendingIntent>();  
      ArrayList<PendingIntent> delPis = new ArrayList<PendingIntent>();  

      int ct = message_parts.size(); 
      for (int i = 0; i < ct; i++) 
      { 
       sentPis.add(i, piSent); 
       delPis.add(i, piDel); 
      } 
      //Log.e("Message Parts", message_parts+""); 
      Log.e("Phone list", list_phone.get(i)); 
      Log.e("Message parts"+i, message_parts.get(i)); 
      sm.sendMultipartTextMessage(list_phone.get(i), null, message_parts, sentPis, delPis); 
      Toast.makeText(getApplicationContext(), " Message sent", Toast.LENGTH_SHORT).show();  

     } 
     } 
     else 
     { 
      // Toast.makeText(getApplicationContext(), "Phone list is empty.. Message not sent", Toast.LENGTH_SHORT).show();  
     } 



} 

답변

0

당신이 추가 필요에 도움이 multiparttext 메시지를 보내 ";" 각 번호 후에.

한 가지 예를 들려주세요. 문제를 확인하고 해결해주세요.

protected void sendMsg(Context context, SmsMessage smsMessage) { 
     SmsManager smsMgr = SmsManager.getDefault(); 
     ArrayList<string> smsMessageText = smsMgr.divideMessage(smsMessage.getMsgBody()); 
     PendingIntent sentPI = PendingIntent.getBroadcast(context, 0, new Intent("SMS_SENT"), 0); 
     PendingIntent deliveredPI = PendingIntent.getBroadcast(context, 0, new Intent("SMS_DELIVERED"), 0); 
     int AddresseesPerMessage = 10; 
     StringBuilder builder = new StringBuilder(); 
     String delim = ""; 

     for (ContactItem c:smsMessage.getAddresseeList()) { 
      // For every phone number in our list 
      builder.append(delim).append(c.getPhoneNumber().toString()); 
      delim=";"; /// if have SAMSUNG devices then delim=", "; 
      if (((smsMessage.getAddresseeList().indexOf(c)+1) % AddresseesPerMessage) == 0 || smsMessage.getAddresseeList().indexOf(c)+1 == smsMessage.getAddresseeList().size()) { 
       // using +1 because index 0 mod 9 == 0 
       for(String text : smsMessageText){ 
        // Send 160 bytes of the total message until all parts are sent 
        smsMgr.sendTextMessage(builder.toString(), null, text, sentPI, deliveredPI); 
       } 
       builder.setLength(0); 
       delim=""; 
      } 
     } 
    } 
0

이 코드

{ 
if (list_phone.size()!=0){ 

//new AddNewCategory().execute(); 
      for (i_m = 0; i_m < len; _mi++){ 
SmsManager sm = SmsManager.getDefault(); 
     ArrayList&lt;String&gt; message_parts = sm.divideMessage(list_MESSAGE_BODY.get(i_m)); 
// Log.e("Message parts 3", message_parts.get(3)); 
     // Log.e("Message parts 4", message_parts.get(4)); 
     Intent iSent = new Intent(); 
     PendingIntent piSent = PendingIntent.getBroadcast(this, 0, iSent, 0); 
     Intent iDel = new Intent(); 
     PendingIntent piDel = PendingIntent.getBroadcast(this, 0, iDel, 0); 
if (message_parts.size() == 1) 
{ 
      String msg = message_parts.get(0); 
      sm.sendTextMessage(list_phone.get(i), null, msg, piSent, piDel); 
      Toast.makeText(getApplicationContext(), " Message sent", Toast.LENGTH_SHORT).show(); 
} 
     else 
{ 
      ArrayList&lt;PendingIntent&gt; sentPis = new ArrayList&lt;PendingIntent&gt;();  
      ArrayList&lt;PendingIntent&gt; delPis = new ArrayList&lt;PendingIntent&gt;();  
int ct = message_parts.size(); 
      for (int i_t = 0; i_t < ct; i_t++) 
{ 
       sentPis.add(i_t, piSent); 
       delPis.add(i_t, piDel); 
      } 
      //Log.e("Message Parts", message_parts+""); 
      Log.e("Phone list", list_phone.get(i)); 
      Log.e("Message parts"+i, message_parts.get(i_m)); 
      sm.sendMultipartTextMessage(list_phone.get(i), null, message_parts, sentPis, delPis); 
      Toast.makeText(getApplicationContext(), " Message sent", Toast.LENGTH_SHORT).show(); 
} 
     } 
     else 
{ 
      // Toast.makeText(getApplicationContext(), "Phone list is empty.. Message not sent", Toast.LENGTH_SHORT).show();  
     } 
} 
시도
관련 문제