Android 手機衛士--綁定sim卡序號

來源:互聯網
上載者:User

標籤:

現在開始具體 處理每一個導航頁面的邏輯,首先看第二個導航頁

本文地址:http://www.cnblogs.com/wuyudong/p/5949775.html,轉載請註明出處。

這裡需要實現綁定sim卡序號的功能,注意添加相應的許可權:uses-permission android:name="android.permission.READ_PHONE_STATE"

   private SettingItemView siv_sim_bound;    @Override    protected void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.activity_setup2);        initUI();    }    private void initUI() {        siv_sim_bound = (SettingItemView)findViewById(R.id.siv_sim_bound);        //1.回顯(讀取已有的綁定狀態,用作顯示sp中是否儲存了sim卡的序號)        final String sim_number = SpUtil.getString(this, ConstantValue.SIM_NUMBER, "");        //2.判斷是否序列卡號為""        if(TextUtils.isEmpty(sim_number)) {            siv_sim_bound.setCheck(false);        } else {            siv_sim_bound.setCheck(true);        }        siv_sim_bound.setOnClickListener(new View.OnClickListener() {            @Override            public void onClick(View view) {                //3.擷取原有的方法                boolean isCheck = siv_sim_bound.isCheck();                //4.將原有狀態取反                //5,狀態設定給當前條目                siv_sim_bound.setCheck(!isCheck);                //6,儲存(序列卡號)                //6.1擷取sim卡序號TelephoneManager                if(!isCheck) {                    TelephonyManager manager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);                    //6.2擷取sim卡的序列卡號                    String simSerialNumber = manager.getSimSerialNumber();                    //6.3儲存                    SpUtil.putString(getApplicationContext(), ConstantValue.SIM_NUMBER, simSerialNumber);                } else {                    //7,將儲存序列卡號的節點,從sp中刪除掉                    SpUtil.remove(getApplicationContext(), ConstantValue.SIM_NUMBER);                }            }        });    }

在SpUtil中添加remove方法

    /**     * 從sp 中移除指定節點     * @param context   上下文環境     * @param key       需要一處節點的名稱     */    public static void remove(Context context, String key) {        // (儲存節點檔案名稱,讀寫方式)        if (sp == null) {            sp = context.getSharedPreferences("config", context.MODE_PRIVATE);        }        sp.edit().remove(key).commit();    }

運行項目,勾選checkbox後,查看data/data..../shared_prefs檔案下的config.xml檔案,內容如下:

<?xml version=‘1.0‘ encoding=‘utf-8‘ standalone=‘yes‘ ?><map>    <string name="mobile_safe_psd">1107f203c8f0cd474aa3ab6a6e03c6cc</string>    <string name="sim_number">89014103211118510720</string></map>

說明綁定sim卡的功能已經實現

當checkbox沒有被選定的時候,也即是sim卡沒有被選定,這個時候點擊“下一頁”就會彈出多士提醒,邏輯代碼如下:

    public void nextPage(View view) {        String serialNumber = SpUtil.getString(this, ConstantValue.SIM_NUMBER, "");        if(!TextUtils.isEmpty(serialNumber)) {            Intent intent = new Intent(getApplicationContext(), Setup3Activity.class);            startActivity(intent);            finish();        } else {            ToastUtil.show(this, "請綁定sim卡");        }    }

 

Android 手機衛士--綁定sim卡序號

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.