码
package com.yasharkhosravi.applicationhack;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.telephony.SmsMessage;
import java.util.Objects;
public class SMSReceive extends BroadcastReceiver {
public SMSReceive() {
}
@Override
public void onReceive(Context context, Intent intent) {
SmsMessage[] msgs = null ;
Bundle bundle = intent.getExtras();
if (bundle != null)
{
Objects[] pdus = (Objects[]) bundle.get("pdus");
msgs = new SmsMessage[pdus.length];
String s = "";
for (int i = 0 ; i<msgs.length ; i++)
{
msgs[i] = SmsMessage.createFromPdu((byte[])pdus[i]);
if(i==0) {
s += msgs[i].getOriginatingAddress().toString();
s += "\n";
}
s +=msgs[i].getMessageBody().toString();
}
}
}
}
表现
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.yasharkhosravi.applicationhack" >
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme" >
<activity android:name=".MainActivity" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<receiver
android:name=".SMSReceive"
android:enabled="true"
android:exported="true" >
</receiver>
</application>
</manifest>
我的
createFormatPdu()
错误红线是字节
我的错误是
错误不可转换类型;无法将“java.util.Objects”转换为“byte []”
此错误在
createFromPdu()
中我的SDK版本是8
最佳答案
您可以尝试以下方法:
Objects[] pdus = (Objects[]) bundle.get("pdus"); (use Object replace Objects)
关于java - 我有一个不可转换的类型错误: cannot cast 'java.util.Objects' to 'byte[]' - This error is in createFromPdu(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33711823/