短信不能使用abortBroadcast pvented $ P $()? [英] SMS cannot be prevented using abortBroadcast()?
问题描述
我工作的一个短信拦截应用程序,其中我使用广播接收器和abortBroadcast()方法 - 尽可能多的脂肪酶建议在这里 - 为prevent邮件到达收件箱,并提醒用户。但对我来说,当我使用模拟器发送短信,SMS消息不会被阻塞,并到达收件箱中,我也得到一个错误:
I am working on a sms blocker application, in which i am using broadcast receiver and abortBroadcast() method - as many ppl have suggested here - to prevent messages from reaching inbox and alerting the user. But in my case, when I send a sms using the emulator, the SMS message won't get blocked, and reaches the inbox, also I get an error :
06-29 09:19:05.854: E/BroadcastReceiver(868): BroadcastReceiver trying to return result during a non-ordered broadcast
不终止应用程序在模拟器,但是当我测试我的手机上的应用程序被终止。
which doesn't terminate the app in the emulator, however the application gets terminated when I test it on my phone.
是的,我已经设置了接收器的优先级为较高的数字,并要求该权限,你在这里看到:
And yes, I have set the receiver's priority to a high number and asked for the permissions as you see here:
<receiver android:name="SMSMonitor">
<intent-filter android:priority="9999999">
<action android:name="android.provider.Telephony.SMS_RECEIVED"></action>
</intent-filter>
</receiver>
<uses-permission android:name="android.permission.RECEIVE_SMS" />
<uses-permission android:name="android.permission.READ_SMS" />
<uses-permission android:name="android.permission.RAISED_THREAD_PRIORITY"/>
最后,这里是我的code:
Finally, here's my code:
public class SMSMonitor extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
boolean isOn = loadState(context,"isOn");// is blocking enabled?
Bundle bundle = intent.getExtras();
Object messages[] = (Object[]) bundle.get("pdus");
SmsMessage smsMessage[] = new SmsMessage[messages.length];
String mAddress;
String mBody;
String mTime;
if(isOn){
// if spam blocking is enabled.
for (int n = 0; n < messages.length; n++) {
smsMessage[n] = SmsMessage.createFromPdu((byte[]) messages[n]);
mAddress=smsMessage[n].getDisplayOriginatingAddress().toString();
mBody=smsMessage[n].getDisplayMessageBody().toString();
mTime=getTime();
if(isBlackList( mAddress)== true) {
this.addLog(mAddress, mBody, mTime);
abortBroadcast();
Toast.makeText(context,"Incoming SMS was blocked and logged.", Toast.LENGTH_LONG).show();
}
}
}
}
}
有个人建议这里的短信广播不能被中止,因为Android将不会允许它。但是,我看到很多人在这里使用abortBroadcast()来阻止短信提示,而且我知道,其实可以阻止短信市场上的一些短信拦截器应用程序。我不知道,如果他们使用abortbroadcast与否。
Some one suggested here that the SMS broadcasts can't be aborted because Android won't allow it. But I have seen many guys here suggested using abortBroadcast() to block a sms, and also I know some SMS blocker apps on the market that actually CAN block SMSs. I don't know if they are using abortbroadcast or not.
任何想法?
推荐答案
作为了Android 1.6的,收到的短信广播(android.provider.Telephony.SMS_RECEIVED)交付作为一个有序播出的 - 这意味着你可以告诉哪些组件应该首先接收广播系统。和我使用的是Android 1.5和广播是无序的!
"As of Android 1.6, incoming SMS message broadcasts (android.provider.Telephony.SMS_RECEIVED) are delivered as an "ordered broadcast" — meaning that you can tell the system which components should receive the broadcast first." and I am using Android 1.5 And the broadcast is non-ordered!
由于这个家伙在这里<一个href=\"http://stackoverflow.com/questions/419184/how-to-delete-an-sms-from-the-inbox-in-android-programmatically\">link
这篇关于短信不能使用abortBroadcast pvented $ P $()?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!