发送短信超过160 charactors [英] sending more than 160 charactors in sms

查看:131
本文介绍了发送短信超过160 charactors的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚发现我的应用程序不能够一次发送超过160个字符。当我试图在同一时间发送超过160个字符它可以在不到160字的罚款。它显示敬酒,但消息不会去任何地方我应该怎么改变发送超过160个字符的已发送邮件。
谢谢结果
这里是code

 公共类MainActivity7扩展ActionBarActivity {
字符串值 ;
    Button按钮;
    TextView的editext2;
    TextView的EDITTEXT;
    @覆盖
    保护无效的onCreate(捆绑savedInstanceState){
        super.onCreate(savedInstanceState);
        的setContentView(R.layout.activity_main_activity7);       EDITTEXT =(的TextView)findViewById(R.id.editText);
        按钮=(按钮)findViewById(R.id.button);
        editext2 =(的TextView)findViewById(R.id.editText2);        意图= getIntent();      editText.setText(a.getStringExtra(项目));
       button.setOnClickListener(新View.OnClickListener(){
           @覆盖
           公共无效的onClick(查看视图){
               sendSMSMessage();
           }
       });    }    私人无效sendSMSMessage(){
        Log.i(发送短信,);
        。字符串PHONENO = editext2.getText()的toString();
        字符串消息= editText.getText()的toString()。
      尝试{
          SmsManager smsManager = SmsManager.getDefault();
          smsManager.sendTextMessage(PHONENO,空,消息,NULL,NULL);
          Toast.makeText(getApplicationContext(),短信发送。
                  Toast.LENGTH_LONG).show(); }
      赶上(例外五){
          Toast.makeText(getApplicationContext(),
                  短信失败,请再试一次,
                  Toast.LENGTH_LONG).show();
          e.printStackTrace();
      }    }
}


解决方案

要发送超过160个字符的短信中,你需要将其发送为多短信。

  SmsManager SM = SmsManager.getDefault();
ArrayList的<串GT;部分= sm.divideMessage(LONG_TEXT);
INT为NumParts = parts.size();ArrayList的<&的PendingIntent GT; sentIntents =新的ArrayList<&的PendingIntent GT;();
ArrayList的<&的PendingIntent GT; deliveryIntents =新的ArrayList<&的PendingIntent GT;();的for(int i = 0; I<为NumParts;我++){
sentIntents.add(PendingIntent.getBroadcast(的getContext(),0,mSendIntent,0));
deliveryIntents.add(PendingIntent.getBroadcast(的getContext(),0,mDeliveryIntent,0));
}sm.sendMultiPartTextMessage(mDestAddr,零,部件,sentIntents,deliveryIntents);

I just found out my app doesn't capable of sending more than 160 characters at a time. it works fine on characters less than 160. when I try to send more than 160 characters at a time. it display "messages sent" toast but message doesn't going anywhere what should I change to send more than 160 characters. thank you
here is the code

public class MainActivity7 extends ActionBarActivity {
String value ;
    Button button;
    TextView editext2;
    TextView editText;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main_activity7);

       editText = (TextView) findViewById(R.id.editText);
        button = (Button) findViewById(R.id.button);
        editext2 = (TextView) findViewById(R.id.editText2);

        Intent a = getIntent();

      editText.setText(a.getStringExtra("item")  );


       button.setOnClickListener(new View.OnClickListener() {
           @Override
           public void onClick(View view) {
               sendSMSMessage();
           }


       });



    }

    private void sendSMSMessage() {
        Log.i("Send SMS", "");
        String phoneno = editext2.getText().toString();
        String message = editText.getText().toString();
      try{
          SmsManager smsManager = SmsManager.getDefault();
          smsManager.sendTextMessage(phoneno,null,message,null,null);
          Toast.makeText(getApplicationContext(),"sms sent.",
                  Toast.LENGTH_LONG).show(); }
      catch (Exception e){
          Toast.makeText(getApplicationContext(),
                  "sms failed,please try again",
                  Toast.LENGTH_LONG).show();
          e.printStackTrace();
      }



    }
}

解决方案

To send more than 160 characters in SMS you need to send it as a multiple SMS.

SmsManager sm = SmsManager.getDefault();
ArrayList<String> parts =sm.divideMessage(LONG_TEXT);
int numParts = parts.size();

ArrayList<PendingIntent> sentIntents = new ArrayList<PendingIntent>();
ArrayList<PendingIntent> deliveryIntents = new ArrayList<PendingIntent>();

for (int i = 0; i < numParts; i++) {
sentIntents.add(PendingIntent.getBroadcast(getContext(), 0, mSendIntent, 0));
deliveryIntents.add(PendingIntent.getBroadcast(getContext(), 0, mDeliveryIntent, 0));
}

sm.sendMultiPartTextMessage(mDestAddr,null, parts, sentIntents, deliveryIntents);

这篇关于发送短信超过160 charactors的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆