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)
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.
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.
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.
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();
}
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With