C++統計軟件應用時光代碼示例。本站提示廣大學習愛好者:(C++統計軟件應用時光代碼示例)文章只能為提供參考,不一定能成為您想要的結果。以下是C++統計軟件應用時光代碼示例正文
讀取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; @Override public 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(); } } }
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); // 依據保留的數據設置狀況 String sim = sp.getString("sim", ""); if (TextUtils.isEmpty(sim)) { siv_sim.setChecked(false); } else { siv_sim.setChecked(true); } // 綁定sim卡 siv_sim.setOnClickListener(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(); } }