Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SMSMessage createFromPdu with extra parameter format

What should I pass as second parameter<"format"> to createFromPdu() method,

SmsMessage currentMessage = SmsMessage.createFromPdu((byte[]) pdusObj[i], format);

As in latest version of android following line of code is deprecated,

SmsMessage currentMessage = SmsMessage.createFromPdu((byte[]) pdusObj[i]);

I have searched on Internet but nothing was clear to me. I have read into android doc too,

http://developer.android.com/reference/android/telephony/SmsMessage.html#createFromPdu(byte[], java.lang.String)

like image 491
Kislay Kumar Avatar asked Oct 01 '15 11:10

Kislay Kumar


People also ask

How to send SMS-SUBMIT PDU using Android telephony?

Use android.telephony.SmsMessage. Get an SMS-SUBMIT PDU for a data message to a destination address & port a SubmitPdu containing the encoded SC address, if applicable, and the encoded message. Returns null on encode error. This method was deprecated in API level 4. Use android.telephony.SmsMessage. Service Centre address. Null means use default.

How to get the TP-layer-length for the given SMS-SUBMIT PDU?

Use android.telephony.SmsMessage. Get the TP-Layer-Length for the given SMS-SUBMIT PDU Basically, the length in bytes (not hex chars) less the SMSC header This method was deprecated in API level 4.

What does the SMS-STATUS-REPORT field indicate?

GSM: For an SMS-STATUS-REPORT message, this returns the status field from the status report. This field indicates the status of a previously submitted SMS, if requested. See TS 23.040, 9.2.3.15 TP-Status for a description of values.


1 Answers

Basically this was introduced for Android Marshmallow to support "3gpp" for GSM/UMTS/LTE messages in 3GPP format or "3gpp2" for CDMA/LTE messages in 3GPP2 format.

Here is the full example for SMSReceiver:

public class SMSReceiver extends BroadcastReceiver {

public void onReceive(Context context, Intent intent)
{
    Bundle myBundle = intent.getExtras();
    SmsMessage [] messages = null;
    String strMessage = "";

    if (myBundle != null)
    {
        Object [] pdus = (Object[]) myBundle.get("pdus");

        messages = new SmsMessage[pdus.length];

        for (int i = 0; i < messages.length; i++)
        {
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
                String format = myBundle.getString("format");
                messages[i] = SmsMessage.createFromPdu((byte[]) pdus[i], format);
            }
            else {
                messages[i] = SmsMessage.createFromPdu((byte[]) pdus[i]);
            }
            strMessage += "SMS From: " + messages[i].getOriginatingAddress();
            strMessage += " : ";
            strMessage += messages[i].getMessageBody();
            strMessage += "\n";
        }

        Log.e("SMS", strMessage);
        Toast.makeText(context, strMessage, Toast.LENGTH_SHORT).show();
    }
}
}
like image 57
Alexi Akl Avatar answered Nov 01 '22 20:11

Alexi Akl