Click here to Skip to main content
15,885,546 members
Please Sign up or sign in to vote.
4.00/5 (3 votes)
See more:
how to block an incoming sms in android programmatically based on content/keywords.
i want generate a sms spam filter in android and i'm unable to retrieve and hence check the message based on its content or any keyword. If the content or keyword is found then message should be blocked.
Posted
Updated 10-Apr-18 20:51pm
Comments
Jeffrey Enzo 18-Apr-11 7:52am    
There already is such a program like you want to build: http://www.playerandroid.com/tools/call-blocker-gold-block-incoming-phone-calls-sms
#realJSOP 18-Apr-11 8:03am    
The wheel is the most reinvented object ever known to man. Why can't he be allowed to reinvent this wheel?
Jeffrey Enzo 18-Apr-11 8:10am    
I am not saying that he can't program such a tool. I refer to that website for his info!

1 solution

Hello
First of all you must add this code to manifest.xml between application tag

XML
<receiver android:name=".MySMSReceiver" >
            
            <intent-filter android:priority="1000"> 
            <action android:name="android.provider.Telephony.SMS_RECEIVED" /> 
    </intent-filter> 
            
        </receiver>


set priority is important becuse it means your application get incoming sms before everything.

after that you should add necessary permisstion for allow you to read and write sms.

then you have to create class that extends BroadcastReceiver and afterward in onReceive method write this code :

@Override
public void onReceive(Context context, Intent intent) {
// TODO Auto-generated method stub


Object[] pdus=(Object[])intent.getExtras().get("pdus");
SmsMessage shortMessage=SmsMessage.createFromPdu((byte[]) pdus[0]);
if(shortMessage.getDisplayMessageBody().contains("//keyword")){

abortBroadcast();
}

hope it help you :)))
 
Share this answer
 
v3
Comments
Dhirubhai Bansal 4-Mar-16 17:08pm    
It is not working.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900