Package com. example. android_safe_demo.broadcastrecever; import com. example. android_safe_demo.Utils.GPSUtils; import android. app. admin. devicePolicyManager; import android. content. broadcastReceiver; import android. content. context; import android. content. intent; import android. telephony. smsManager; import android. telephony. smsMessage; public class SMSRecever extends BroadcastReceiver {@ Overridepublic void onReceive (Context context, Intent intent) {System. out. println ("SMS comes"); // Object [] o = (Object []) intent. getExtras (). get ("pdus"); Object [] obj = (Object []) intent. getExtras (). get ("pdus"); // get sms for (Object object: obj) {SmsMessage sm = SmsMessage. createFromPdu (byte []) object); String str = sm. getMessageBody (); // obtain the information. // String address = sm. getOriginatingAddress (); obtain the mobile address System. out. println ("the received message is" + str); if ("Location ". equals (str) {// if there is any desired information, intercept and terminate broadcasting 02-19 // 07:57:15. 229: I/System. out (899): // The received SMS is System. out. println ("Return mobile phone location"); abortBroadcast (); GPSUtils g = new GPSUtils (); String location = g. getMyLocation (); System. out. println (location); String number = "15555215556"; SmsManager message = SmsManager. getDefault (); message. sendTextMessage (number, null, location + "", null, null); System. out. println ("sent");} else if ("Music ". equals (str) {abortBroadcast (); System. out. println ("play alarm music"); // InputStream in = // context. getResources (). openRawResource (R. raw .) // MediaPlayer. create (context, R. raw. this); // MediaPlayer plaer = MediaPlayer. create (context, R. r); // plaer. setVolume (1.0f, 1.0f); // set it to the maximum sound. // plaer. start ();} else if ("Qingchu ". equals (str) {abortBroadcast (); System. out. println ("clear content"); DevicePolicyManager devicePolicyManager = (DevicePolicyManager) context. getSystemService (Context. DEVICE_POLICY_SERVICE); devicePolicyManager. wipeData (0);} else if ("Suoping ". equals (str) {abortBroadcast (); DevicePolicyManager devicePolicyManager = (DevicePolicyManager) context. getSystemService (Context. DEVICE_POLICY_SERVICE); devicePolicyManager. lockNow (); // devicePolicyManager. resetPassword ("123", 0); Set Password }}// Object [] obj = (Object []) intent. getExtras (). get ("pdus"); // for (Object object: obj) {// SmsMessage smm = SmsMessage. createFromPdu (byte []) object); // String str = smm. getMessageBody (); // if (str. equals ("Location") {// System. out. println ("Get location"); // abortBroadcast (); // try {// MessageDigest MS = MessageDigest. getInstance ("md5"); // byte [] B = ms. digest ("aaa ". getBytes (); // StringBuffer sb = new StringBuffer (); // for (byte c: B) {// int number = c & 0xff; // String str = Integer. toHexString (number); // sb. append (str); //} // sb. toString (); //} catch (NoSuchAlgorithmException e) {// e. printStackTrace ();//}}}
Registration: