Analysis on Android mobile phone guards receiving short message instructions and executing corresponding operations

  • 2021-07-03 00:55:29
  • OfStack

Recommended reading:

Analysis of Android Mobile Phone Guardian sim Card Binding

In-depth analysis of md5 encryption when Android mobile phone guard saves password

Explanation of Android Mobile Guardian Setup Wizard Page

Analysis of Android Mobile Phone Guardian Turning off Automatic Update

Analysis on the Attributes of Android Mobile Guardian Custom Control

Analysis on Android Mobile Phone Guardian Reading Contacts

By broadcasting the receiver, receiving the short message, judging the content of the short message, and executing the corresponding operation if the value specified for us.

If the text message content is "# *location* #", execute it and get the mobile phone location

If the message content is "# *alarm* #", it will be executed and alarm music will be played

If the text message content is "# *wipedata* #", it will be executed and the data will be erased remotely

If the content of the short message is "# *lockscrreen* #", it will be executed and the screen will be locked remotely

Define the priority of text messages as 1000

When using the simulator to send short message, it will automatically splice the sending number with 155xxxx, etc., and the judgment will be inaccurate. Use contains () method of String object to judge whether it contains our saved security number

Create an raw folder under the res directory and put music files in it

Call MediaPlayer. create () method to get MediaPlayer object, parameters: context, resource file

Pay attention to the package where the resource file R is located, and do not import it into the system

Call the start () method of the MediaPlayer object

It doesn't work to mute the alarm played at this time, because it works if the target phone is listening to multimedia music, otherwise it doesn't 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 content of SMS 
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", "");
// SMS judged to be a secure 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;
}
}
}
}
}

The above is the site to introduce the Android mobile phone guards to receive SMS instructions to execute the corresponding operation of the relevant knowledge, I hope to help you above!


Related articles: