Listen to incoming multipart SMS message

百般思念 提交于 2019-12-08 03:15:26

问题


I can catch newly incoming SMS messages. But if that is a multipart message, my broadcast receiver receives all parts of the message at several times.

Is there a way to receive the whole message at one time - like default messaging app does?


回答1:


Holy...!

After reading the Android source (this file), I realize that this is such a stupid question...

Here is my receiver:

@Override
public void onReceive(Context context, Intent intent) {
    Log.d(ClassName, "received SMS");

    Bundle bundle = intent.getExtras();
    if (bundle != null) {
        Object[] pdus = (Object[]) bundle.get("pdus");
        // here is what I need, just combine them all  :-)
        final SmsMessage[] messages = new SmsMessage[pdus.length];
        Log.d(ClassName, String.format("message count = %s", messages.length));
        for (int i = 0; i < pdus.length; i++) {
            messages[i] = SmsMessage.createFromPdu((byte[]) pdus[i]);
        }
    }
}// onReceive()

Oops... I was too lazy to look at my code. I already got all parts of the message at a time.



来源:https://stackoverflow.com/questions/10032945/listen-to-incoming-multipart-sms-message

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!