Java On Receive SMS广播接收器仅适用于android 2.3.3

Java On Receive SMS广播接收器仅适用于android 2.3.3,java,android,sms,smsmanager,Java,Android,Sms,Smsmanager,这是我的短信接收Java类。它在Android2.3.3 Emulator上工作得很好,当它收到短信时,它会先烤短信接收者的号码,然后烤短信内容 public class IncomingSms extends BroadcastReceiver { public static final String ACTION = "android.provider.Telephony.SMS_RECEIVED"; @Override public void onReceiv

这是我的短信接收Java类。它在Android2.3.3 Emulator上工作得很好,当它收到短信时,它会先烤短信接收者的号码,然后烤短信内容

public class IncomingSms extends BroadcastReceiver  {

    public static final String ACTION = "android.provider.Telephony.SMS_RECEIVED";

    @Override
    public void onReceive(Context context, Intent intent) {
        // TODO Auto-generated method stub
        if (intent.getAction().equals(ACTION)){
            Bundle bundle = intent.getExtras();
            if (bundle != null){
                Object[] pdus = (Object[]) bundle.get("pdus");
                SmsMessage[] messages = new SmsMessage[pdus.length];
                for (int i = 0; i < pdus.length; i++){
                    messages[i] = SmsMessage.createFromPdu((byte[]) pdus[i]);
                }
                for (SmsMessage message : messages){

                    String strMessageFrom = message.getDisplayOriginatingAddress();
                    String strMessageBody = message.getDisplayMessageBody();

                    Toast.makeText(context, "SMS Message received from:" +strMessageFrom, Toast.LENGTH_LONG).show();
                    Toast.makeText(context, "SMS Message content" +strMessageBody, Toast.LENGTH_LONG).show();


                }
            }
        }
    }
}
public class IncomingSms扩展广播接收器{
public static final String ACTION=“android.provider.Telephony.SMS_RECEIVED”;
@凌驾
公共void onReceive(上下文、意图){
//TODO自动生成的方法存根
if(intent.getAction().equals(ACTION)){
Bundle=intent.getExtras();
if(bundle!=null){
Object[]pdus=(Object[])bundle.get(“pdus”);
SmsMessage[]messages=新SmsMessage[pdus.length];
对于(int i=0;i
显示

    <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="xxxx.xxx.xxxxxxx" >
    <uses-permission android:name="android.permission.RECEIVE_SMS"></uses-permission>
    <uses-permission android:name="android.permission.READ_SMS" />
    <uses-permission android:name="android.permission.SEND_SMS"></uses-permission>

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name=".MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />

            </intent-filter>
        </activity>

        <receiver android:name=".IncomingSms">
            <intent-filter>
                <action android:name="android.provider.Telephony.SMS_RECEIVED" />
            </intent-filter>
        </receiver>
    </application>

</manifest>

但是,当我在android 4.0 Emulator、android 5.1.1和我真正的android 5.0.2设备上运行这段代码时,它的工作方式与android 2.3.3 Emulator不一样(在接收短信时不要发送消息)

有什么想法吗