标签:
绑定sim卡
ublic class Setup2Activity extends BaseSetupActivity {
private SettingItemView sivSim;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_setup2);
sivSim = (SettingItemView) findViewById(R.id.siv_sim);
String sim = mPref.getString("sim", null);
if (!TextUtils.isEmpty(sim)) {
sivSim.setChecked(true);
} else {
sivSim.setChecked(false);
}
sivSim.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if (sivSim.isChecked()) {
sivSim.setChecked(false);
mPref.edit().remove("sim").commit();// 删除已绑定的sim卡
} else {
sivSim.setChecked(true);
// 保存sim卡信息
TelephonyManager tm = (TelephonyManager) getSystemService(TELEPHONY_SERVICE);
String simSerialNumber = tm.getSimSerialNumber();// 获取sim卡序列号
System.out.println("sim卡序列号:" + simSerialNumber);
mPref.edit().putString("sim", simSerialNumber).commit();// 将sim卡序列号保存在sp中
}
}
});
}
@Override
public void showNextPage() {
// 如果sim卡没有绑定,就不允许进入下一个页面
String sim = mPref.getString("sim", null);
if (TextUtils.isEmpty(sim)) {
ToastUtils.showToast(this, "必须绑定sim卡!");
return;
}
startActivity(new Intent(this, Setup3Activity.class));
finish();
// 两个界面切换的动画
overridePendingTransition(R.anim.tran_in, R.anim.tran_out);// 进入动画和退出动画
}
@Override
public void showPreviousPage() {
startActivity(new Intent(this, Setup1Activity.class));
finish();
// 两个界面切换的动画
overridePendingTransition(R.anim.tran_previous_in,
R.anim.tran_previous_out);// 进入动画和退出动画
}
}
/**
* 监听手机开机启动的广播
*
* @author Kevin
*
*/
public class BootCompleteReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
SharedPreferences sp = context.getSharedPreferences("config",
Context.MODE_PRIVATE);
boolean protect = sp.getBoolean("protect", false);
// 只有在防盗保护开启的前提下才进行sim卡判断
if (protect) {
String sim = sp.getString("sim", null);// 获取绑定的sim卡
if (!TextUtils.isEmpty(sim)) {
// 获取当前手机的sim卡
TelephonyManager tm = (TelephonyManager) context
.getSystemService(Context.TELEPHONY_SERVICE);
String currentSim = tm.getSimSerialNumber() + "111";// 拿到当前手机的sim卡
if (sim.equals(currentSim)) {
System.out.println("手机安全");
} else {
System.out.println("sim卡已经变化, 发送报警短信!!!");
String phone = sp.getString("safe_phone", "");// 读取安全号码
// 发送短信给安全号码
SmsManager smsManager = SmsManager.getDefault();
smsManager.sendTextMessage(phone, null,
"sim card changed!", null, null);
}
}
}
}
}
<receiver android:name=".receiver.BootCompleteReceiver" >
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
标签:
原文地址:http://www.cnblogs.com/liuyu0529/p/4921663.html