Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Android already has the constant definition <code>ENCODING_16BIT</code>, <code>ENCODING_7BIT</code>, <code>ENCODING_8BIT</code>, <code>ENCODING_UNKNOWN</code> in the <a href="http://developer.android.com/reference/android/telephony/SmsMessage.html" rel="nofollow">SMSMessage</a> class which correspond to Data Coding Scheme in <a href="http://www.3gpp.org/ftp/Specs/html-info/0338.htm" rel="nofollow">3GPP TS 03.38</a>. However, it's funny that they are not used in return value of public methods.</p> <p>Hence, the best solution is:</p> <ol> <li>Get the whole SMS TPDU bytes using <code>getPdu()</code></li> <li>Parse the bytes according to <a href="http://www.3gpp.org/ftp/Specs/html-info/0340.htm" rel="nofollow">3GPP TS 03.40</a> (section 9) to get the DCS byte (for SMS deliver: 1 byte TP-MTI/MMS/RP/UDHI/SRI, 2-12 bytes TP-OA, 1 byte TP-PID, and then the DCS byte)</li> <li>Parse the DCS byte according to section 5 of 3GPP TS 03.38.</li> </ol> <p>Sample code for parsing the DCS byte is as follow:</p> <pre><code>public static byte getSmsDcsType(byte dcs) { // Notes: // ------ // the (SMS) DCS value according to 3GPP TS 03.38 / TS 23.038 is coded as follow: // 0xxx00xx = GSM 7-bit default alphabet (packed format) // 0xxx01xx = 8-bit data (unpacked-format) // 0xxx10xx = UCS2 uncompressed format // 0xxx11xx = reserved // 10xxxxxx = reserved // 110xxxxx = GSM 7-bit default alphabet (packed format) // 1110xxxx = UCS2 uncompressed format // 111100xx = GSM 7-bit default alphabet (packed format) // 111101xx = 8-bit data (unpacked-format) // 11111xxx = reserved if (((byte) (dcs &amp; (byte) 0x8C) == 0x00) || ((byte) (dcs &amp; (byte) 0xE0) == (byte) 0xC0) || ((byte) (dcs &amp; (byte) 0xFC) == (byte) 0xF0)) { return SmsMessage.ENCODING_7BIT; } else if (((byte) (dcs &amp; (byte) 0x8C) == 0x04) || ((byte) (dcs &amp; (byte) 0xFC) == (byte) 0xF4)) { return SmsMessage.ENCODING_8BIT; } else if (((byte) (dcs &amp; (byte) 0x8C) == 0x08) || ((byte) (dcs &amp; (byte) 0xF0) == (byte) 0xE0)) { return SmsMessage.ENCODING_16BIT; } return SmsMessage.ENCODING_UNKNOWN; } </code></pre>
 

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