收听传入的多部分SMS消息 [英] Listen to incoming multipart SMS message

查看:90
本文介绍了收听传入的多部分SMS消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以捕获新收到的SMS消息.但是,如果这是多部分消息,则我的广播接收器会多次接收消息的所有部分.

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?

推荐答案

圣洁的!!

阅读Android源代码后(这个文件),我意识到这是一个愚蠢的问题...

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

这是我的接收者:

@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.

这篇关于收听传入的多部分SMS消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆