如何发送超过160个字符的短信?

时间:2022-01-05 20:15:40

How to send big SMS in android. I used :

如何在android中发送大短信。我用了 :

SmsManager sms = SmsManager.getDefault();
sms.sendTextMessage(contactNos[j], null,msgs[i], sentPI, deliveredPI);

this code work only for 160 character message. i also use

此代码仅适用于160个字符的消息。我也用

ArrayList<String> msgsplit=sms.divideMessage(msgs[i]);
ArrayList<PendingIntent> listOfIntents = new ArrayList<PendingIntent>(); 

for (int k=0; k < msgsplit.size(); k++){  
    Intent sentIntent = new Intent(); 
    PendingIntent pi = PendingIntent.getBroadcast(MultipleMsg.this, 0, sentIntent, PendingIntent.FLAG_CANCEL_CURRENT);  
    listOfIntents.add(pi);  
}
// sendMessage(contactNos[j],msgs[i]);
sms.sendMultipartTextMessage(contactNos[j],null,msgsplit, listOfIntents, null);

But it sends junk character in the message. Can anyone help me?

但它会在邮件中发送垃圾字符。谁能帮我?

4 个解决方案

#1


31  

Junk characters? method sendMultipartTextMessage only send text message. If you want to send non text message, you should look to method sendDataMessage. Below is the code excerpt from android cts. It has example on how to send long messages.

垃圾人物?方法sendMultipartTextMessage只发送短信。如果要发送非文本消息,则应查看方法sendDataMessage。以下是android cts的代码摘录。它有关于如何发送长消息的示例。

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)

#2


43  

Try below code might help

尝试以下代码可能有所帮助

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

#3


3  

The emulator send the junk characters in that code during certain problem so use apk in real mobile , and check the code , I am sure that your application will not send junk message..All the best.

模拟器在某些问题中发送该代码中的垃圾字符,因此在真正的移动设备中使用apk,并检查代码,我确信您的应用程序不会发送垃圾邮件。所有最好的。

#4


0  

You should get specific Short Code from SMSC, for sending SMS which having characters more than 160.

你应该从SMSC获得特定的短代码,用于发送字符超过160的短信。

#1


31  

Junk characters? method sendMultipartTextMessage only send text message. If you want to send non text message, you should look to method sendDataMessage. Below is the code excerpt from android cts. It has example on how to send long messages.

垃圾人物?方法sendMultipartTextMessage只发送短信。如果要发送非文本消息,则应查看方法sendDataMessage。以下是android cts的代码摘录。它有关于如何发送长消息的示例。

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)

#2


43  

Try below code might help

尝试以下代码可能有所帮助

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

#3


3  

The emulator send the junk characters in that code during certain problem so use apk in real mobile , and check the code , I am sure that your application will not send junk message..All the best.

模拟器在某些问题中发送该代码中的垃圾字符,因此在真正的移动设备中使用apk,并检查代码,我确信您的应用程序不会发送垃圾邮件。所有最好的。

#4


0  

You should get specific Short Code from SMSC, for sending SMS which having characters more than 160.

你应该从SMSC获得特定的短代码,用于发送字符超过160的短信。