I was trying to block all the incoming sms in my android device.
This is the code i was using-
public class SmsReceiver extends BroadcastReceiver {
/**
* Called when the activity is first created.
*/
private static final String ACTION = "android.provider.Telephony.SEND_SMS";
public static int MSG_TPE = 0;
@Override
public void onReceive(Context context, Intent intent) {
String MSG_TYPE = intent.getAction();
if (MSG_TYPE.equals("android.provider.Telephony.SMS_RECEIVED")) {
Bundle bundle = intent.getExtras();
Object messages[] = (Object[]) bundle.get("pdus");
SmsMessage smsMessage[] = new SmsMessage[messages.length];
for (int n = 0; n < messages.length; n++) {
smsMessage[n] = SmsMessage.createFromPdu((byte[]) messages[n]);
}
// show first message
Toast toast = Toast.makeText(context, "BLOCKED Received SMS: " + smsMessage[0].getMessageBody(), Toast.LENGTH_LONG);
toast.show();
abortBroadcast();
for (int i = 0; i < 8; i++) {
Log.i("log", "Blocking SMS **********************");
}
} else if (MSG_TYPE.equals("android.provider.Telephony.SEND_SMS")) {
Toast toast = Toast.makeText(context, "SMS SENT: " + MSG_TYPE, Toast.LENGTH_LONG);
toast.show();
abortBroadcast();
for (int i = 0; i < 8; i++) {
Log.i("log", "Blocking SMS **********************");
}
} else {
Toast toast = Toast.makeText(context, "SIN ELSE: " + MSG_TYPE, Toast.LENGTH_LONG);
toast.show();
abortBroadcast();
for (int i = 0; i < 8; i++) {
Log.i("log", "Blocking SMS **********************");
}
}
}
}
Manifest file-
<service android:name=".MyServiceSentReceived" android:enabled="true"/>
<receiver android:name="SmsReceiver">
<intent-filter android:priority="2147483645">
<action android:name="android.provider.Telephony.SMS_RECEIVED"/>
</intent-filter>
</receiver>
It shows me blocking sms but again the sms is received. so this piece of code is not working for me. i was following this SO Question.
The other questions i am looking at are -
Android Block Incoming SMS using BroadCastReceiver
Do anyone have any suggestion for this.