android - 在模拟器之间发送短信

标签 android android-emulator sms

我正在尝试从模拟器向模拟器发送短信。它可以工作,但只能使用非常有限的字符集(ASCII 的子集)。如果我在消息中包含以下任何字符,则这些字符第一次出现后的任何内容都将变成乱码:

|, ^, {, }, €, [, ~, ] and \

(但我还需要非 ASCII 字符,例如希伯来字母表)

例如,如果我发送 Hello ^ World,它将变成 Hello ^

或者 [Hello:World] 变成类似 [ e ]

这是我使用的代码:

void sendSms(final String toNumber, final String message) {
    final SmsManager sm = SmsManager.getDefault();
    if (message.getBytes().length <= 160) {
        sm.sendTextMessage(toNumber, null, message, null, null);
    } else {
        ArrayList<String> msgStringArray = sm.divideMessage(message);
        sm.sendMultipartTextMessage(toNumber, null, msgStringArray, null, null);
    }
    Log.v(TAG, "sendSms: " + toNumber + ", " + message + ", " + message.length() + " chars / " + message.getBytes().length + " bytes");
}

我用来接收消息的代码在这里:Receive an read SMS with correct encoding and convert to UTF8

最佳答案

这似乎是模拟器中的错误:https://code.google.com/p/android/issues/detail?id=202723

Though I don't have an immediate solution, it is worth mentioning that Emulator 2.0 includes a UI for sending SMS messages to the virtual device, and the aforementioned characters all work fine when sent from that UI. If you need to do some testing with a device receiving (but not sending) an SMS message containing those characters, that should do the trick until we track down this bug. You can get access to Emulator 2.0 from the preview release channel as part of tools 25.0.

关于android - 在模拟器之间发送短信,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35847301/

相关文章:

android - 在 Android 中将替代短信发送器设置为默认发送器

android - 如何修复android中的 'android.view.ViewGroup.jumpDrawablesToCurrentState(ViewGroup.java:5035)'错误

iOS:在应用程序处于事件状态时阅读短信,就像 Drivesafe.ly 一样

android - 如何在android中显示一个人的当前年龄(25岁11个月20天)?

android - Widget Application ForceCloses 安装

android-emulator - 使用zip文件在Android Studio中安装Android模拟器

android - 主机切换网络后如何刷新安卓模拟器网络连接?

android - 从 SIM 卡获取短信

java - 如何将选项卡 fragment Activity 转换为没有选项卡的正常 Activity

java - onStartLoading() 和forceLoad() 是在哪里调用和实现的?