[Android] mobile guard receives SMS commands and performs corresponding operations. android receives SMS messages.

Source: Internet
Author: User

[Android] mobile guard receives SMS commands and performs corresponding operations. android receives SMS messages.

The receiver receives the text message and determines the content of the text message. If the value is specified, the corresponding operation is performed.

 

If the text message content is "# * location * #", run the command to obtain the mobile phone location.

If the text message content is "# * alarm * #", run the command to play the alarm music.

If the text message content is "# * wipedata * #", run the command to clear data remotely.

If the text message content is "# * lockscrreen * #", run the command to remotely lock the screen.

 

Set the SMS priority to 1000.

 

When the simulator is used to send short messages, it will automatically splice 155xxxx and so on to the sending number, and the determination will be inaccurate. Use the contains () method of the String object to determine whether it contains the Security number we saved.

 

Create a raw folder in the res directory and put the music file in it.

Call MediaPlayer. create () to obtain the MediaPlayer object, parameters: context, resource file

Note that the package where resource file R is located should not be imported into the system

Call the start () method of the MediaPlayer object

In this case, the mute of the playing alarm does not work, because if the target mobile phone is listening to music, multimedia is used, otherwise it does not work.

SmsReceiver. java

Package com. qingguow. mobilesafe. receiver; import com. qingguow. mobilesafe. r; import android. content. broadcastReceiver; import android. content. context; import android. content. intent; import android. content. sharedPreferences; import android. media. mediaPlayer; import android. telephony. smsMessage; import android. widget. toast; public class SmsReceiver extends BroadcastReceiver {private SharedPreferences sp; @ Override public void onReceive (Context context, Intent intent) {sp = context. getSharedPreferences ("config", Context. MODE_PRIVATE); // get the text message content Object [] 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", ""); // if (secSender. equals (sender) {switch (body) {case "# * alarm * #": // send alarm music // Toast. makeText (context, "playing alarm music", 1 ). show (); MediaPlayer mp = MediaPlayer. create (context, R. raw. alarm); mp. start (); abortBroadcast (); break; default: break ;}}}}}

 

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.