You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I was trying to send sms from plyer recently and struggled to understand why some of them did not work. I learned in the process that:
sms are actually limited to 160 encoded characters,
when they don't contains ascii characters, the message is utf-16 encoded hence the limit on the message becomes quite low.
there are two methods provided by android.telephony.SmsManager
divideMessage gets the message and returns an array of single sms messages
sendMultipartTextMessage gets as input the array returned by divideMessage and sends several sms as if it was a single message
I realize that this is was happens behind the hood in the default sms app.
You can see here that the application informs me that the message will be actually split in two and that I only have 20 characters left in my message.
When removing the ê, I can type more words before the application let me know of the limit.
So, I tried replacing sms.sendTextMessage(recipient, None, message, None, None) by sms.sendMultipartTextMessage(recipient, None, sms.divideMessage(message), None, None)
And it worked like a charm. I don't have message silently failing anymore.
I'm asking therefore if a pull request doing just that would be accepted? I don't know anough about android and the sms world to tell if there are reasons not to do that.
What do you think?
The text was updated successfully, but these errors were encountered:
In any case, if we want to stick with sendTextMessage, it would be good to add a check to raise an error when the sms will not be sent.
Before finding sendMultipartTextMessage, I added this code, so that at least, I knew when this situation happened:
forencodingin"ascii", "utf-16":
try:
length=len(message.encode(encoding))
iflength>=160:
raiseException(f"Message to long {length}")
else:
breakexceptUnicodeEncodeError:
passelse:
raiseException("I should not reach that part")
I was trying to send sms from plyer recently and struggled to understand why some of them did not work. I learned in the process that:
I realize that this is was happens behind the hood in the default sms app.
You can see here that the application informs me that the message will be actually split in two and that I only have 20 characters left in my message.
When removing the
ê
, I can type more words before the application let me know of the limit.So, I tried replacing
sms.sendTextMessage(recipient, None, message, None, None)
bysms.sendMultipartTextMessage(recipient, None, sms.divideMessage(message), None, None)
And it worked like a charm. I don't have message silently failing anymore.
I'm asking therefore if a pull request doing just that would be accepted? I don't know anough about android and the sms world to tell if there are reasons not to do that.
What do you think?
The text was updated successfully, but these errors were encountered: