[Android] mobile guard binds a SIM card and androidsim
Update:
If the broadcast cannot be started, it seems that the system of the higher version is disabled.
You can also use adb to send boot broadcasts.
Adb shell am broadcast-a android. intent. action. BOOT_COMPLETED
Not tested yet. Go back and try again.
======================================
Read the serial number of the sim card and save it. If the sim card is changed and the sim card is considered as a thief, a warning is issued.
Read SIM card serial number
Get the TelephonyManager object and use getSystemService (TELEPHONY_SERVICE)
Call the getSimSerialNumber () method of the TelephonyManager object to obtain the serial number of the String type.
Save the serial number in SharedPreences.
Permission required for android. permission. READ_PHONE_STATE
Check whether the SIM card is changed
Use the broadcast receiver to listen to the boot broadcast of the mobile phone
Create a new package xxx. receiver and a new class BootCompleteReceiver. java
Register the configuration file, add the <er ER> node, and set the name android: name = "xxx"
Add intent filter <intent-filter> node
Add an action <action/> node and set the listening action name android. intent. action. BOOT_COMPLETED.
In the onReceive () method in the BootCompleteReceiver class, receive the broadcast, read the current SIM card serial number, and compare the previously saved SIM card serial number. If not, send a text message to the security number.
Android: perission. RECEIVE_BOOT_COMPLETED
BootCompleteReceiver. java
Package com. qingguow. mobilesafe. explorer; import android. content. broadcastReceiver; import android. content. context; import android. content. intent; import android. content. sharedPreferences; import android. telephony. telephonyManager; import android. widget. toast; public class BootCompleteReceiver extends BroadcastReceiver {private TelephonyManager tm; private SharedPreferences sp; @ Override public void onReceive (Context cotext, Intent arg1) {sp = cotext. getSharedPreferences ("config", Context. MODE_PRIVATE); // read the current SIM card serial number tm = (TelephonyManager) cotext. getSystemService (Context. TELEPHONY_SERVICE); String relSim = tm. getSimSerialNumber (); // read the previously saved String saveSim = sp. getString ("sim", ""); // if (saveSim. equals (relSim) {} else {// sends an alert message to the security number System. out. println ("SIM card changed"); Toast. makeText (cotext, "SIM card changed", 1 ). show ();}}}
SecGuide2Activity. java
Package com. qingguow. mobilesafe; import android. content. intent; import android. content. sharedPreferences; import android. content. sharedPreferences. editor; import android. OS. bundle; import android. telephony. telephonyManager; import android. text. textUtils; import android. view. view; import android. view. view. onClickListener; import com. qingguow. mobilesafe. ui. settingItemView; public class SecGuide2Activity extends BaseSecGuideActivity {private SettingItemView siv_sim; private SharedPreferences sp; private TelephonyManager telephonyManager; @ Override protected void onCreate (Bundle detail) super. onCreate (savedInstanceState); setContentView (R. layout. activity_lost_find2); siv_sim = (SettingItemView) findViewById (R. id. siv_sim); sp = getSharedPreferences ("config", MODE_PRIVATE); telephonyManager = (TelephonyManager) getSystemService (TELEPHONY_SERVICE); // set the status String sim = sp Based on the saved data. getString ("sim", ""); if (TextUtils. isEmpty (sim) {siv_sim.setChecked (false);} else {siv_sim.setChecked (true);} // bind a sim card secret (new OnClickListener () {@ Override public void onClick (View arg0) {String sim = telephonyManager. getSimSerialNumber (); Editor editor = sp. edit (); String simSp = sp. getString ("sim", ""); if (TextUtils. isEmpty (simSp) {siv_sim.setChecked (true); editor. putString ("sim", sim);} else {siv_sim.setChecked (false); editor. putString ("sim", "");} editor. commit () ;}}) ;}public void nextStep (View v) {showNext () ;}public void preStep (View v) {showPre ();} @ Override public void showNext () {Intent intent = new Intent (this, SecGuide3Activity. class); startActivity (intent); finish () ;}@ Override public void showPre () {Intent intent = new Intent (this, SecGuide1Activity. class); startActivity (intent); finish ();}}