安卓短信广播接收器没有得到全文较大短信 [英] android: sms broadcast receiver not getting full text for larger sms

查看:218
本文介绍了安卓短信广播接收器没有得到全文较大短信的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

看来,如果有一些较大的文本短信来的时候,它会被切断某种原因使整不来的短信中,这里是我的code:

It seems that if an SMS with some larger text comes, it is cut for some reason so not whole sms comes in, here is my code:

public class SmsReceiver extends BroadcastReceiver {
   // vars here

    @Override
    public void onReceive(Context context, Intent intent) {

        // Get SMS map from Intent
        Bundle extras = intent.getExtras();

        if (extras != null) {
            // Get received SMS array
            Object[] smsExtra = (Object[]) extras.get(SMS_EXTRA_NAME);

            String address = "";
            String body = "";

            for (int i = 0; i < smsExtra.length; ++i) {
                SmsMessage sms = SmsMessage.createFromPdu((byte[]) smsExtra[i]);
                body = sms.getMessageBody().toString();
                address = sms.getOriginatingAddress();
            }

      // show the popup
      Intent intnt = new Intent(context, ShowNotification.class);
      intnt.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
      intnt.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
      intnt.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

      intnt.putExtra("address", address);
      intnt.putExtra("body", body);
      context.startActivity(intnt);

        }
    }
}

现在让我们假设短信是:

Now let's assume sms text was:

Pellentesque居住者morbi tristique senectus等netus等malesuada脂肪酸甲酯交流turpis egestas。前庭tortor华富,feugiat简历,ultricies eget,tempor坐阿梅德,赌注。 Donec欧盟自由人坐阿梅德华富egestas永远忠诚。 Aenean ultricies英里简历EST。Mauris placerat eleifend狮子座。 Quisque坐阿梅德EST等SAPIEN ullamcorper pharetra。

和我展示从上面烤面包广播接收器接收到短信,正在显示只有最后几句敬酒,甚至如果我通过这个短信的身体到另一个弹出的意图,只有尽可能多的文本越过如图敬酒:

And i show received sms from above broadcast receiver in toast, only last few words are being shown in toast or even if I pass this sms body to another popup intent, only as much text is passed over as shown in toast:

int duration = Toast.LENGTH_LONG;
Toast toast = Toast.makeText(context,  body, duration);
toast.show();

所以,出于某种原因,而不是整个短信在未来:(

So for some reason not whole sms text is coming in :(

谁能告诉如何处理呢?正如我所看到的其他短信应用程序,如短信弹出或GO短信,他们得到在弹出的对话或全SMS文本和显示。

Can anyone tell how to handle this ? As I have seen other sms apps such as SMS Popup or Go SMS Pro, they do get full sms text and show in popup or conversations.

感谢您的帮助。

推荐答案

好了,所以我想通了,我用的是只是得到最后一个短信code,只需将所有短信

Ok so I figured it out, the code I was using was only getting one last sms, just need to append all sms:

body = sms.getMessageBody().toString();

应该是:

body += sms.getMessageBody().toString();

这篇关于安卓短信广播接收器没有得到全文较大短信的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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