我刚发现我的应用无法一次发送超过160个字符。它适用于小于160的字符。当我尝试一次发送超过160个字符时。它显示“发送的消息”吐司,但消息不会到达任何地方我应该更改以发送超过160个字符。 谢谢你 这是代码
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();
}
}
}
答案 0 :(得分:1)
要在短信中发送超过160个字符,您需要将其作为多个短信发送。
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);