How to send non-printable characters via SMS

Does anyone know how to send unprintable characters via SMS on Android?

I tried the following code, but it does not work ... The receiver will not receive the correct line.

String msg = "Testing special char" +(char) 3; sendSMS(num,msg);//defined method 

Or is there another way to insert some tags in the SMS so that the recipient can perform some actions accordingly?

+4
source share
2 answers

By default, you send sms text messages in ascii format. Try sending binary SMS.

+2
source

As there is an Android tag to the question, here is what I found while researching a topic (code from codetheory.in ).

Send:

 // Get the default instance of SmsManager SmsManager smsManager = SmsManager.getDefault(); String phoneNumber = "9999999999"; byte[] smsBody = "Let me know if you get this SMS".getBytes(); short port = 6734; // Send a text based SMS smsManager.sendDataMessage(phoneNumber, null, port, smsBody, null, null); 

Reception:

 public class SmsReceiver extends BroadcastReceiver { private String TAG = SmsReceiver.class.getSimpleName(); public SmsReceiver() { } @Override public void onReceive(Context context, Intent intent) { // Get the data (SMS data) bound to intent Bundle bundle = intent.getExtras(); SmsMessage[] msgs = null; String str = ""; if (bundle != null){ // Retrieve the Binary SMS data Object[] pdus = (Object[]) bundle.get("pdus"); msgs = new SmsMessage[pdus.length]; // For every SMS message received (although multipart is not supported with binary) for (int i=0; i<msgs.length; i++) { byte[] data = null; msgs[i] = SmsMessage.createFromPdu((byte[]) pdus[i]); str += "Binary SMS from " + msgs[i].getOriginatingAddress() + " :"; str += "\nBINARY MESSAGE: "; // Return the User Data section minus the // User Data Header (UDH) (if there is any UDH at all) data = msgs[i].getUserData(); // Generally you can do away with this for loop // You'll just need the next for loop for (int index=0; index < data.length; index++) { str += Byte.toString(data[index]); } str += "\nTEXT MESSAGE (FROM BINARY): "; for (int index=0; index < data.length; index++) { str += Character.toString((char) data[index]); } str += "\n"; } // Dump the entire message // Toast.makeText(context, str, Toast.LENGTH_LONG).show(); Log.d(TAG, str); } } } 
0
source

Source: https://habr.com/ru/post/1388547/


All Articles