[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 ;}}}}}