By broadcasting the recipient, receive the text message, the content of the message to judge, if the value we specified to do the corresponding action
If the message content is "#*location*#" on the execution, get the phone location
If the message content is "#*alarm*#" on the execution, play alarm music
If the text message content is "#*wipedata*#" on execution, remote erase data
If the message content is "#*lockscrreen*#" on the execution, Remote lock screen
Define SMS priority as
When using the simulator to send the short interest, the sending number will be automatically stitched on 155xxxx and so on, the judgment time will be inaccurate, using The String object's contains () method to determine whether to include our saved security number
Create the Raw folder in the res directory and put the music files in
Call the mediaplayer.create () method to get the MediaPlayer Object, Parameters: Context, resource file
Note that the resource file R is located in the package, do not lead to the system
Call the start () method of the MediaPlayer Object
The mute of the alerts played at this point is not working because the target phone is playing with multimedia if it is listening to music.
Smsreceiver.java
PackageCom.qingguow.mobilesafe.receiver;ImportCOM.QINGGUOW.MOBILESAFE.R;ImportAndroid.content.BroadcastReceiver;ImportAndroid.content.Context;Importandroid.content.Intent;Importandroid.content.SharedPreferences;ImportAndroid.media.MediaPlayer;ImportAndroid.telephony.SmsMessage;ImportAndroid.widget.Toast; Public classSmsreceiverextendsBroadcastreceiver {PrivateSharedpreferences sp; @Override Public voidOnReceive (Context context, Intent Intent) {SP=context.getsharedpreferences ("config", context.mode_private); //Get SMS ContentObject[] objs= (object[]) Intent.getextras (). Get ("PDUs"); for(Object obj:objs) {smsmessage SMS=SMSMESSAGE.CREATEFROMPDU ((byte[]) obj); String Body=Sms.getmessagebody (); String Sender=sms.getoriginatingaddress (); String Secsender=sp.getstring ("Secphone", "" "); //a text message that determines the security number if(Secsender.equals (sender)) {Switch(body) { Case"#*alarm*#"://Send alarm Music//Toast.maketext (Context, "play alarm Music", 1). Show ();MediaPlayer mp=mediaplayer.create (context, r.raw.alarm); Mp.start (); Abortbroadcast (); Break; default: Break; } } } }}
[Android] Mobile defender receives SMS instruction to perform corresponding operation