我正在尝试使用我的Android应用程序发送短信文本消息,但是当我运行它时我没有收到任何内容
这是代码
int minSms = 100001;
int maxSms = 999998;
Random rSms = new Random();
int iSms = rSms.nextInt(maxSms - minSms +1) + minSms;
try {
SmsManager sms = SmsManager.getDefault();
PendingIntent sentPI;
String SENT = "SMS_SENT";
sentPI = PendingIntent.getBroadcast(getActivity(), 0,new Intent(SENT), 0);
sms.sendTextMessage(mobileNumber, null, Integer.toString(iSms), sentPI, null);
Toast.makeText(getActivity(), "SMS sent.",
Toast.LENGTH_SHORT).show();
} catch (Exception e) {
Toast.makeText(getActivity(),
"SMS failed, please try again.",
Toast.LENGTH_LONG).show();
e.printStackTrace();
}
我正在测试我自己的手机号码,我不打算分享,但格式为07789123456
我需要添加任何区号吗,还是应该使用直的11位数字?
答案 0 :(得分:1)
请查看SMS Manager send mutlipart message when there is less than 160 characters。我很确定您要发送的文字很长。根据您使用的字母表(即包括表情符号),消息限制为70个字符。您必须将邮件拆分为多部分邮件:
SmsManager sms = SmsManager.getDefault();
ArrayList<String> parts = sms.divideMessage(longMessage);
sms.sendMultipartTextMessage(phoneNumber, null, parts, null, null);