发送一条短信,自己的程序中截断不了系统的SMS_RECEIVED广播

我自己创建的一个程序,在程序中自定义一个广播接收器类,同时想截断这个广播:
package com.example.smstest;

import android.os.Bundle;
import android.app.Activity;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.telephony.gsm.SmsMessage;
import android.view.Menu;
import android.widget.TextView;

public class MainActivity extends Activity {

private TextView sender;
private TextView content;
private IntentFilter receiveFilter;
private MessageReceiver messageReceiver;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    sender=(TextView)findViewById(R.id.sender);
    content=(TextView)findViewById(R.id.content);
    receiveFilter=new IntentFilter();
    receiveFilter.addAction("android.provider.Telephony.SMS_RECEIVED");
    receiveFilter.setPriority(100);
    messageReceiver=new MessageReceiver();
    registerReceiver(messageReceiver, receiveFilter);
}



@Override
protected void onDestroy() {
    // TODO Auto-generated method stub
    super.onDestroy();
    unregisterReceiver(messageReceiver);
}



class MessageReceiver extends BroadcastReceiver{

    @Override
    public void onReceive(Context context, Intent intent) {
        // TODO Auto-generated method stub

        Bundle bundle=intent.getExtras();
        Object[] pdus=(Object[]) bundle.get("pdus");
        SmsMessage[] messages=new SmsMessage[pdus.length];
        for(int i=0;i<messages.length;i++){
            messages[i]=SmsMessage.createFromPdu((byte[])pdus[i]);

        }
        String address=messages[0].getOriginatingAddress();
        String fullMessage="";
        for(SmsMessage message : messages){
            fullMessage += message.getMessageBody();
        }
        sender.setText(address);
        content.setText(fullMessage);
        abortBroadcast();
    }








}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.main, menu);
    return true;
}

}
但是运行程序后,系统自带短信程序仍可以接收到,拦截失败。如图:
图片说明
配置文件:
<?xml version="1.0" encoding="utf-8"?>
package="com.example.smstest"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk
    android:minSdkVersion="14"
    android:targetSdkVersion="18" />
<uses-permission android:name="android.permission.RECEIVE_SMS"/>

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name="com.example.smstest.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>
</application>

2个回答

系统自带的短信已被注册为最终广播接收者,也就是说无论怎么拦截,它都能收到这个广播!

你可以看看最终广播接受者,以及信息安全这方面的,就知道了

wuzg1020
wuzg1020 恩,谢谢
接近 4 年之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐