Android SMS Blocker

Source: Internet
Author: User

do not waste words focus:

Androidmanifest.xml The file code is as follows:

<uses-permission android:name= "Android.permission.RECEIVE_SMS"/> <!--intercept SMS (that is, accept shorter privileges)-->< Uses-permission android:name= "Android.permission.RECEIVE_BOOT_COMPLETED"/> <!--start receiving (optional permissions) when boot is started <receiver android:name= "Com.demo.artshell.broadcastreceiverdemo.InterceptReceiver" > <!--here is not set up Android: Enable and Android:exported properties, refer to official documents--      <!--here priority is 1000, assuming your phone does not have other third-party SMS blocker software, such as 360, Otherwise, other third-party software blocking permissions too high cause you to have the app intercept SMS-      <intent-filter android:priority= "" >      <action android: Name= "Android.provider.Telephony.SMS_RECEIVED"/> <!--It's written dead, see official documents--      </intent-filter></ Receiver>

This does not require activity code, only a broadcastreceiver subclass, the source is as follows:

Import Android.content.broadcastreceiver;import Android.content.context;import Android.content.intent;import Android.os.bundle;import Android.telephony.smsmessage;import Android.util.log;import Android.widget.Toast;import Java.text.simpledateformat;import Java.util.date;public class Interceptreceiver extends Broadcastreceiver {public STA    Tic final String TAG = "Interceptreceiver";    public static final String action_sms_received = "Android.provider.Telephony.SMS_RECEIVED"; Public Interceptreceiver () {} @Override public void OnReceive (context context, Intent Intent) {log.i (TAG, "--        -------------interceptreceiver onreceive ()----------------");            if (Action_sms_received.equals (Intent.getaction ())) {Bundle carrycontent = Intent.getextras ();                if (carrycontent! = null) {StringBuilder SB = new StringBuilder ();             Get all incoming messages via PDUs, get SMS content object[] PDUs = (object[]) carrycontent.get ("PDUs");   Build an array of SMS objects smsmessage[] mges = new Smsmessage[pdus.length]; for (int i = 0, len = pdus.length; i < Len; i++) {//Get a single SMS content, save in PDU format and generate SMS object mg                Es[i] = SMSMESSAGE.CREATEFROMPDU ((byte[]) pdus[i]); } for (Smsmessage mge:mges) {sb.append ("SMS From:"). Append (mge.getdisplayoriginatingaddr                    ESS ()). Append ("\ n"). Append ("message content:"). Append (Mge.getmessagebody ()). Append ("\ n");                    Date senddate = new Date (Mge.gettimestampmillis ());                    SimpleDateFormat format = new SimpleDateFormat ("Yyyy-mm-dd HH:mm:ss");                Sb.append ("SMS Send Time:"). Append (Format.format (senddate)); } log.i (Tag,sb.tostring ());                Print log records Toast.maketext (Context,sb.tostring (), Toast.length_long). Show (); This.abortbroadcast (); No longer propagates down}}}}

next through the real Machine debugging: Dial 1008611 to observe the mobile receipt SMS is intercepted, the program in the SDK 4.0.3 (Huawei Mobile) on the test pass, the other SDK version has not been tested!

the second type of interception, refer to the link

How to implement SMS Blocker on Android 4.4

Android SMS Blocker

Related Article

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.