createFromPdu((byte [])smsobject [i])无法在BroadCastReceiver中强制转换为byte []

时间:2014-10-05 08:16:03

标签: java android

我的目标是需要从BroadcastReceiver获取SMS详细信息,获取SMS后我将这些信息存储在Object中,之后无法将其转换为字节以将其存储在字符串变量中... 这是我的代码,我是java和android的新手plz帮我这个

    public void onReceive(Context context, Intent intent) {
    String Orgi_Phonenumber = "";
    final Bundle bundle = intent.getExtras();
    if (bundle != null) {
        Log.i("MyMessage", "start reading message information");
        Object[] smsobject = new Object[] { (Object) bundle.get("pdus") };
        for (int i = 0; i < smsobject.length; i++) {
            SmsMessage CurrentMessage = SmsMessage
                    .createFromPdu((byte[]) smsobject[i]);
            Orgi_Phonenumber += CurrentMessage.getOriginatingAddress();
        }

    }
}

下面是创建问题

SmsMessage CurrentMessage = SmsMessage.createFromPdu((byte[]) smsobject[i]);

错误是 java.lang.RuntimeException:无法启动接收器com.example.receivesms.IncomingSms:java.lang.ClassCastException:java.lang.Object []无法强制转换为byte []

请告诉我上述错误的原因是什么

1 个答案:

答案 0 :(得分:0)

Object[] smsobject = (Object[]} bundle.get("pdus");