Reputation: 1503
As I have read from multiple sources that there are some changes in APIs in Android 4.4 onwards etc. True enough, my code is not working now :(
Basically, I want to read incoming SMS and filter possible spams by deleting the spam SMSes. Since deletion could not be done now, I am trying to just prompt that the newly received SMS is potential spam.
Below is my source snippet for non Android 4.4 versions:
public class Sms extends BroadcastReceiver{
private static final String ACTION = "android.provider.Telephony.SMS_DELIVER";
public void onReceive(Context context, Intent intent) {
Bundle pudsBundle = intent.getExtras();
Object[] pdus = (Object[]) pudsBundle.get("pdus");
SmsMessage messages =SmsMessage.createFromPdu((byte[]) pdus[0]);
// Log.i(TAG, messages.getMessageBody());
if(messages.getMessageBody().contains("Adv")) {
abortBroadcast();
}
}
}
My Manifest file:
<receiver android:name=".Sms" android:permission="android.permission.BROADCAST_SMS">
<intent-filter>
<action android:name="android.provider.Telephony.SMS_DELIVER" />
</intent-filter>
</receiver>
What must I change to make it work for Android 4.4? I just want to read the incoming SMSes without doing abortBroadcast.
Upvotes: 1
Views: 3831
Reputation: 1503
Managed to find it. You can refer to this tutorial:
Explains how to read incoming SMSes. Do note that certain functions like abort broadcast, delete sms will not be working from Android 4.4 onwards unless the user chooses your app as the default messaging app.
Upvotes: 0
Reputation: 2664
Since 4.4 only default SMS app will receive SMS_DELIVER_ACTION broadcasts. Other apps must now use SMS_RECEIVED_ACTION broadcasts, this is introduced in API level 19 and can not be aborted.
Upvotes: 1