[Android] Mobile defender receives SMS instruction to perform corresponding operation

Source: Internet
Author: User

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

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.