MTK Read/Write IMEI from App
生活随笔
收集整理的這篇文章主要介紹了
MTK Read/Write IMEI from App
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
?直接上代碼, no bb 那么多 , 要system id權(quán)限, 加到系統(tǒng)里面做接口比較好。
/*** add modify imei start*/private int mPhoneId = 0;private Phone mGsmPhone = null;private static final int EVENT_AT_CMD_DONE = 1004;public void writeImei(String phoneImei){String atCmdLine = "AT+EGMR=1,7,\""+phoneImei+"\"";int phoneId = 0;if (mPhoneId < 0 || mPhoneId >= TelephonyManager.getDefault().getPhoneCount()) {mPhoneId = 0;}mGsmPhone = PhoneFactory.getPhone(mPhoneId);try {byte[] rawData = atCmdLine.getBytes();byte[] cmdByte = new byte[rawData.length + 1];System.arraycopy(rawData, 0, cmdByte, 0, rawData.length);cmdByte[cmdByte.length - 1] = 0;mGsmPhone.invokeOemRilRequestRaw(cmdByte,mHandler.obtainMessage(EVENT_AT_CMD_DONE));} catch (Exception ee) {ee.printStackTrace();}}public Handler mHandler = new Handler() {public void handleMessage(Message msg) {AsyncResult ar;switch (msg.what) {case EVENT_AT_CMD_DONE:ar = (AsyncResult) msg.obj;handleAtCmdResponse(ar);break;default:break;}}};public void handleAtCmdResponse(AsyncResult ar) {if (ar.exception != null) {Log.e(TAG, "The response of command is failed");// showInfo("AT command is failed to send");} else {try {byte[] rawData = (byte[]) ar.result;Log.e(TAG, "HexDump:" + HexDump.dumpHexString(rawData));String txt = new String(rawData, "UTF-8");Log.e(TAG, "The resopnse is " + txt);// showInfo("AT command is sent:" + txt);} catch (NullPointerException e) {// showInfo("Something is wrong");e.printStackTrace();} catch (UnsupportedEncodingException ee) {ee.printStackTrace();}}}public static String readImei(Context context){String imei = "";try {TelephonyManager tm = (TelephonyManager) context.getSystemService("phone");if(Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP){imei = tm.getDeviceId();}else {Method method = tm.getClass().getMethod("getImei");imei = (String) method.invoke(tm);}} catch (Exception e) {e.printStackTrace();}return imei;}/*** add modify imei end*/總結(jié)
以上是生活随笔為你收集整理的MTK Read/Write IMEI from App的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: MTK Read/Write Ether
- 下一篇: Android JNI 报错(signa