我创建了一个用于阻止来自android(jellybean)的传入调用和文本消息的应用程序。阻止调用的功能完美无缺。但是当我将阻止文本消息的功能添加到同一个应用程序时,消息不会被阻止 我的清单文件是:
<receiver android:name=".CallBarring" android:permission="android.permission.READ_PHONE_STATE">
<intent-filter android:priority="1000"><action android:name="android.intent.action.PHONE_STATE" />
</intent-filter>
<intent-filter>
<action android:name="android.provider.Telephony.SMS_RECEIVED" />
</intent-filter>
</receiver>
<receiver android:name=".SMSReceiver" android:enabled="true" android:exported="true" android:permission="android.permission.BROADCAST_SMS">
<intent-filter android:priority="5822">
<action android:name="android.provider.Telephony.SMS_RECEIVED"/>
</intent-filter>
</receiver>
mainActivity的oncreate方法是:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Initialization of the button of the Main screen
b1 = (Button) findViewById(R.id.btn1);
b1.setOnClickListener(this);
b2=(Button)findViewById(R.id.btn2);
b2.setOnClickListener(this);
b3=(Button)findViewById(R.id.btn3);
b3.setOnClickListener(this);
b4=(Button)findViewById(R.id.btn4);
b4.setOnClickListener(this);
TextView textView=(TextView)findViewById(R.id.textView);
Context context=getApplicationContext();
TelephonyManager manager = (TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE);
String carrierName = manager.getNetworkOperatorName();
textView.setText(carrierName);
String tag1="calling";
sms = new SMSReceiver();
IntentFilter intentSMS = new IntentFilter(
"android.provider.Telephony.SMS_RECEIVED");
intentSMS.setPriority(2147483647);
registerReceiver(sms, intentSMS);
String tag="messaging";
Log.d(tag," hello!!!! started messaging activity");
Intent intent1 = new Intent(this,SMSReceiver.class);
// EditText edt=(EditText)findViewById(R.id.editText);
// intent.putExtra("message",(CharSequence) edt.getText().toString());
intent1.setAction("android.provider.Telephony.SMS_RECEIVED");
sendBroadcast(intent1);
Log.d(tag,"sent intent for messaging");