Android学习之获取手机的IMEI号

/*获取手机IMEI号*/
private static String getDeviceId(Context context) {
    String id = "test";
    //android.telephony.TelephonyManager
    TelephonyManager mTelephony = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
    if (ContextCompat.checkSelfPermission(context, Manifest.permission.READ_PHONE_STATE) == PackageManager.PERMISSION_GRANTED) {
        if (mTelephony.getDeviceId() != null)
        {
            id = mTelephony.getDeviceId();
        } else {
            //android.provider.Settings;
            id = Settings.Secure.getString(context.getApplicationContext().getContentResolver(), Settings.Secure.ANDROID_ID);
        }
    }
    return id;
}

猜你喜欢

转载自blog.csdn.net/ReCclay/article/details/81676991