Android SMS Blocker

Source: Internet
Author: User

Android 4+ version requires users to actively add Broadreceiver

1. manifest file

<Manifestxmlns:android= "Http://schemas.android.com/apk/res/android" Package= "Com.example.smslistener"Android:versioncode= "1"Android:versionname= "1.0" >    <USES-SDKandroid:minsdkversion= "8"android:targetsdkversion= "+" />    <uses-permissionAndroid:name= "Android.permission.RECEIVE_SMS"/>     <ApplicationAndroid:allowbackup= "true"Android:icon= "@drawable/ic_launcher"Android:label= "@string/app_name"Android:theme= "@style/apptheme" >                <ActivityAndroid:name=". Mainactivity "Android:label= "@string/app_name" >            <Intent-filter>                <ActionAndroid:name= "Android.intent.action.MAIN" />                <categoryAndroid:name= "Android.intent.category.LAUNCHER" />            </Intent-filter>        </Activity>                        <receiverAndroid:name=". Smsreceiver ">            <!--Priority priorities Highest: 1000 lowest: -1000 -            <Intent-filterandroid:priority= "+">                <ActionAndroid:name= "Android.provider.Telephony.SMS_RECEIVED"/>            </Intent-filter>        </receiver>            </Application></Manifest>

2.mainActivity

 Package Com.example.smslistener; Import android.app.Activity; Import Android.os.Bundle;  Public class extends Activity {    @Override    protectedvoid  onCreate (Bundle Savedinstancestate) {                super. OnCreate (savedinstancestate);        Finish ();    }}

4.SmsReceicer

 PackageCom.example.smslistener;ImportAndroid.content.BroadcastReceiver;ImportAndroid.content.Context;Importandroid.content.Intent;ImportAndroid.telephony.SmsMessage; Public classSmsreceiverextendsBroadcastreceiver {@Override Public voidOnReceive (Context context, Intent Intent) {System.out.println ("The message came ..."); //Get SMSObject[] PDUs = (object[]) Intent.getextras (). Get ("PDUs");  for(Object pdu:pdus) {smsmessage SMS= SMSMESSAGE.CREATEFROMPDU ((byte[]) PDU); String Body=Sms.getmessagebody (); String Address=sms.getoriginatingaddress (); System.out.println ("Body:" +body); System.out.println ("Address:" +address); if("4444". Equals (address)) {                //Intercept SMSAbortbroadcast (); }                    }            }}

Android SMS Blocker

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.