A brief analysis of Android phone defender SIM card binding _android

Source: Internet
Author: User

Read the SIM card serial number, save it, once the SIM has changed, think it is the thief's SIM card, issued a warning

Read the SIM card serial number

Gets the Telephonymanager object, through Getsystemservice (Telephony_service)

Call the Getsimserialnumber () method of the Telephonymanager object, and get the string type serial number

Keep the serial number in the sharedpreences.

Need to add permissions Android.permission.READ_PHONE_STATE

Detect if a SIM card has changed

Use broadcast receivers to monitor the phone's power-on broadcast

Create a new package Xxx.receiver, create a new class Bootcompletereceiver.java

Listing file registration, add <receiver> node, set name android:name= "XXX"

Add Intent Filter <intent-filter> node

Add action <action/> node, set listener action name Android.intent.action.BOOT_COMPLETED

In the Bootcompletereceiver class inside the OnReceive () method, receives the broadcast, reads the current SIM card serial number, compares the previously saved SIM card serial number, if does not have the same to send the text message to the security number

Monitoring boot requires permission android:perission. receive_boot_completed

Bootcompletereceiver.java

Package com.qingguow.mobilesafe.receiver;
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);
Reads 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", "");
After the judgement of
the message if (Savesim.equals (Relsim)) {
}else{
//Send alarm short 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 savedinstancestate) {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);
State String sim = sp.getstring ("Sim", "") based on saved data if (Textutils.isempty (SIM)) {siv_sim.setchecked (false);} else {Siv_sim.setChecked (TRUE); }//Bind SIM card Siv_sim.setonclicklistener (new Onclicklistener () {@Override public void OnClick (View arg0) {String SIM = Tel
Ephonymanager.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 Sho Wpre () {Intent Intent = new Intent (this, secguide1activity.class); startactivity (Intent); Finish ();}}
Related Article

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.