I'm developing an application for Android that sends commands to a remote device via SMS. The commands used are all common text messages, and some of them are started with the prefix A@@
. To test the application I have sent some "commands" to an Android 4.3 phone and an Android 2.3.
When I run the application on Android 4.3, SMS is normally received on any device, but if I use the application to send commands from an Android 2.3 the commands are received as A¿¿
by the Android 4.3 phone but arrive normally as A@@
on both an Android 2.3 and an iPhone. In the "target" device, which uses a GSM modem, the message arrives as A
(character "A" plus 2 spaces - ASCII symbol 0x20), so I suspect sending is using an encoding different. The strange thing is that the @
symbol is not even an extended ASCII character, so I wonder why it would have been encoded in another charset other than ASCII.
Can anyone explain what's going on? If the Android 2.3 device is actually using another encoding , is there any way to force it to ASCII before sending the SMS?
The function that sends the commands is as follows:
@Override
public void sendCommand(String command) {
SmsManager sms=SmsManager.getDefault();
PendingIntent piSent=PendingIntent.getBroadcast(this, 0,
new Intent("SMS_SENT"), 0);
PendingIntent piDelivered=PendingIntent.getBroadcast(this, 0,
new Intent("SMS_DELIVERED"), 0);
String phone = txtPhone.getText().toString();
sms.sendTextMessage(phone, null, command, piSent, piDelivered);
}
Where the parameter command
is always the concatenation of the prefix with some other text, like this:
String SmsPrefix = new String("A@@");
sendCommand(SmsPrefix + "AT+DEACT");