Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The correct way to do this would be by using sendDataMessage from SmsManager class. Here's a little code (SMSSender):</p> <pre><code>SmsManager smsMgr = SmsManager.getDefault(); smsMgr.sendDataMessage(phoneNumber, null, (short) myApplicationPort, messageString.getBytes(), sentIntent, deliveryIntent); </code></pre> <p>Here's another little code (SMSReceiver):</p> <pre><code> Bundle bundle = intent.getExtras(); if (bundle != null) { Object[] pdusObj = (Object[]) bundle.get("pdus"); SmsMessage[] messages = new SmsMessage[pdusObj.length]; // getting SMS information from PDU for (int i = 0; i &lt; pdusObj.length; i++) { messages[i] = SmsMessage.createFromPdu((byte[]) pdusObj[i]); } for (SmsMessage currentMessage : messages) { if (!currentMessage.isStatusReportMessage()) { String messageBody = currentMessage.getDisplayMessageBody(); byte[] messageByteArray = currentMessage.getPdu(); // skipping PDU header, keeping only message body int x = 1 + messageByteArray[0] + 19 + 7; // I'm not sure about this last line, as I'm not converting the bytes back to string, so test it out String realMessage = new String(messageByteArray, x, messageByteArray.length-x); </code></pre> <p>Here's what you should add to your AndroidManifest.xml:</p> <pre><code> &lt;receiver android:name=".SMSReceiver"&gt; &lt;intent-filter&gt; &lt;action android:name="android.intent.action.DATA_SMS_RECEIVED" /&gt; &lt;data android:scheme="sms" /&gt; &lt;data android:host="localhost" /&gt; &lt;data android:port="12345" /&gt;&lt;!-- this number should be the same as the `myApplicationPort` from above!!! --&gt; &lt;/intent-filter&gt; &lt;/receiver&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload