I am trying to make an Android app regarding text messages. I got a source code from googling and it is works fine. However, it does not work with text messages over 80 bytes or MMS. It seems that the onReceive
method cannot catch those long text messages.
Did I miss something or make any mistakes?
Here are the permissions I added..
android.permission.READ_SMS,
android.permission.RECEIVE_SMS,
android.permission.SEND_SMS,
android.permission.WRITE_SMS,
android.permission.READ_PHONE_STATE,
android.permission.INTERNET,
android.permission.ACCESS_NETWORK_STATE,
android.permission.RECEIVE_MMS,
android.permission.WRITE_EXTERNAL_STORAGE
This is my code:
public class MySMSMonitor extends BroadcastReceiver {
private static String ACTIONNAME = "android.provider.Telephony.SMS_RECEIVED";
@Override
public void onReceive(Context context, Intent intent) {
if (intent != null && intent.getAction() != null
&& ACTIONNAME.compareToIgnoreCase(intent.getAction()) == 0) {
Object[] pdu = (Object[]) intent.getExtras().get("pdus");
SmsMessage[] msg = new SmsMessage[pdu.length];
for (int i = 0; i < msg.length; i++) {
msg[i] = SmsMessage.createFromPdu((byte[]) pdu[i]);
}
StringBuilder sb = new StringBuilder();
for(SmsMessage allMsg : msg) {
sb.append(allMsg.getDisplayOriginatingAddress() + "&");
sb.append(allMsg.getDisplayMessageBody() + "&");
sb.append(allMsg.getTimestampMillis() + "&");
}
android.util.Log.i("SMS monitor", "data received = " + sb.toString());
}
}
}
Please give me some advice.