权限
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
private void setPhoneStateManifest(){if (ActivityCompat.checkSelfPermission(this, Manifest.permission.READ_PHONE_STATE) != PackageManager.PERMISSION_GRANTED) {// toast("需要动态获取权限");ActivityCompat.requestPermissions(MainActivity.this, new String[]{Manifest.permission.READ_PHONE_STATE}, REQUEST_PHONE_STATE);}else{// toast("不需要动态获取权限");TelephonyManager tm = (TelephonyManager)getSystemService(TELEPHONY_SERVICE);String IMEI = tm.getDeviceId();Log.i(TAG,"IMEI:" + IMEI);} }@Override public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {if (requestCode == REQUEST_PHONE_STATE && grantResults.length == 1 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {TelephonyManager tm = (TelephonyManager)getSystemService(TELEPHONY_SERVICE);String IMEI = tm.getDeviceId();Log.i(TAG,"IMEI:" + IMEI);} }