2013-11-04 32 views
3

我正尝试从我的Android应用程序发送短信。一切工作正常,但一些文字丢失。这里是我的代码:消息未完整发送。某些文本丢失

String phoneNumber = "99********"; //Masked the number intentionally. 
String message = ""; 
message += "This is Prabha, and thanks for using my application. "; 
message += "Hope you enjoy this application. "; 
message += "If you face any problem or issue, you can report the issue to our "; 
message += "official mail id: [email protected]"; 

SmsManager smsManager = SmsManager.getDefault(); 
smsManager.sendTextMessage(phoneNumber, null, message, null, null); 

我收到消息,但它不是满的。一些文字丢失。我只得到了如下文字:

This is Prabha, and thanks for using my application. Hope you enjoy this application. If you face any problem or issue, you can report the issue to our officia

我已经添加下面的权限在AndroidManifest.xml

<uses-permission android:name="android.permission.SEND_SMS" /> 

我无法找到为什么剩余的文本被截断。我应该添加其他权限还是需要更改设置?任何想法或帮助将不胜感激。

谢谢。

+0

您可以从我的回答让代码:http://stackoverflow.com/questions/19083158/send-sms-until-it-是成功/ 19084559#19084559请upvote如果它可以帮助你。 – cYrixmorten

回答

1

您需要使用sendMultipartTextMessage()方法可用于SmsManager类。

sendTextMessage()SmsManager可用的方法只能发送长度为160个字符的文本消息。

要发送多部分SMS,请使用SmsManager类中提供的divideMessage()方法来分割消息。然后在sendMultipartTextMessage()发送此parts作为参数,如下图所示:

SmsManager smsManager = SmsManager.getDefault(); 
ArrayList<String> parts = smsManager.divideMessage(message); 
smsManager.sendMultipartTextMessage(phoneNumber, null, parts, null, null);