I am working on an sms-blocker application in which I use the broadcast receiver and the abortBroadcast () method, as suggested by many ppl here - so that messages do not fall into the Inbox folder and do not warn the user. But in my case, when I send sms using the emulator, the SMS message will not be blocked and will reach incoming mail, also I get an error message:
06-29 09:19:05.854: E/BroadcastReceiver(868): BroadcastReceiver trying to return result during a non-ordered broadcast
which does not interrupt the application in the emulator, however the application terminates when I test it on my phone.
And yes, I set the priority of the receiver to a large number and asked for permission, 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"/>
Finally, here is my code:
public class SMSMonitor extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
boolean isOn = loadState(context,"isOn");
Bundle bundle = intent.getExtras();
Object messages[] = (Object[]) bundle.get("pdus");
SmsMessage smsMessage[] = new SmsMessage[messages.length];
String mAddress;
String mBody;
String mTime;
if(isOn){
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();
}
}
}
}
}
- , SMS , Android . , abortBroadcast() sms, SMS , SMS-. , abortbroadcast .
?