读取sim卡的序列号,保存起来,一旦sim发生变更了,认为是小偷的sim卡,发出警告
读取sim卡序列号
获取TelephonyManager对象,通过getSystemService(TELEPHONY_SERVICE)
调用TelephonyManager对象的getSimserialNumber()方法,得到String类型的序列号
把序列号保存在SharedPreences里面
需要加权限 androID.permission.READ_PHONE_STATE
检测sim卡是否变更
使用广播接收者,监听手机的开机广播
新建一个包 xxx.receiver,新建一个类BootCompleteReceiver.java
清单文件注册一下,添加<receiver>节点,设置名称androID:name=”xxx”
添加意图过滤器<intent-filter>节点
添加动作<action/>节点,设置监听动作名称androID.intent.action.BOOT_COMPLETED
在BootCompleteReceiver类里面的onReceive()方法里,接收到广播,读取当前的sim卡序列号,比较之前保存的sim卡序列号,如果不一样就发送短信给安全号码
监听开机启动需要权限 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;@OverrIDepublic voID onReceive(Context cotext,Intent arg1) {sp=cotext.getSharedPreferences("config",Context.MODE_PRIVATE);//读取当前的sim卡序列号tm=(TelephonyManager) cotext.getSystemService(Context.TELEPHONY_SERVICE);String relSim=tm.getSimserialNumber();//读取之前保存的String saveSim=sp.getString("sim","");//判断后发短信if(saveSim.equals(relSim)){}else{//发送报警短息给安全号码System.out.println("sim卡变更了");Toast.makeText(cotext,"sim卡变更了",1).show();}}} @H_419_49@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;@OverrIDeprotected 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);// 根据保存的数据设置状态String sim = sp.getString("sim","");if (TextUtils.isEmpty(sim)) {siv_sim.setChecked(false);} else {siv_sim.setChecked(true);}// 绑定sim卡siv_sim.setonClickListener(new OnClickListener() {@OverrIDepublic 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();}@OverrIDepublic voID showNext() {Intent intent = new Intent(this,SecGuIDe3Activity.class);startActivity(intent);finish();}@OverrIDepublic voID showPre() {Intent intent = new Intent(this,SecGuIDe1Activity.class);startActivity(intent);finish();}}@H_419_49@ 总结以上是内存溢出为你收集整理的浅析Android手机卫士sim卡绑定全部内容,希望文章能够帮你解决浅析Android手机卫士sim卡绑定所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)