首页 > 解决方案 > 带有百分比符号的 html 的 SMS 正文文本会导致 android 应用程序崩溃

问题描述

每当我在我的短信 html 链接的正文中添加一个 % 时,例如:短信(?或 & 分隔取决于 ios android):

a href="sms:555555555?body=Hello123 % testing!"target="_parent">            
Click /a

它使我在 android 上的消息传递应用程序崩溃,但在 iOS 上它很好。我也尝试对其进行编码,但这似乎不起作用。关于如何逃避这个的任何线索?

编辑:这只发生在谷歌信息上,三星信息是好的

标签: androidhtmlsms

解决方案


我遇到了同样的问题并花了很多时间,但解决方案非常简单。需要将 '%' 替换为以下之一: 百分号变化

短信正文编码功能:

function encodeSMSText(text) {
  const updatedText = text.replace(/%/g, String.fromCharCode(0xFF05));
   return encodeURIComponent(updatedText)
    .replace(/[!'()*]/g, function(c) {
      return '%' + c.charCodeAt(0).toString(16);
    });
}


推荐阅读