Android发送短信超过160个字符

时间:2014-09-02 03:18:05

标签: android sms

您好我正在尝试将短信发送到具有不同文本正文的不同手机号码,我的代码也发送超过160个字符的短信但它只向一个号码发送不是全部,现在我想向所有联系人发送多部分短信息list.pls帮助

private void 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 个答案:

没有答案