Get the App
SLTechnology News&Howtos  ›  Development  › 

How to replace IMEI with Android_id in Android

Shulou Source: shulou.com Published: 2022-05-31 22:49:14 09月21日 Update

This article mainly introduces the relevant knowledge of how to replace IMEI with Android_id in Android, the content is detailed and easy to understand, the operation is simple and fast, and it has a certain reference value, I believe you will have something to gain after reading this Android article on how to replace IMEI with Android_id. Let's take a look.

Pre-work:

The project configuration is upgraded to the corresponding version 29

CompileSdkVersion: 29

BuildToolsVersion: '29.0.0'

MinSdkVersion: 19

TargetSdkVersion: 29

JavaVersion: JavaVersion.VERSION_1_8

The old version of the method to get IMEI:

Public static String getIMEI (Context context) {String deviceId = null; try {TelephonyManager tm = (TelephonyManager) context .getSystemService (Context.TELEPHONY_SERVICE); deviceId = tm.getDeviceId (); if (deviceId = = null | | ".equals (deviceId)) {return getLocalMacAddress (context);}} catch (Exception e) {e.printStackTrace () If (deviceId = = null | | ".equals (deviceId)) {return getLocalMacAddress (context); / / get the Mac address. In the Android 9p version, the address will change randomly and cannot be used as a unique identity. It can be removed. }} return deviceId;}

Android Q gets IMEI method

Public static String getIMEI (Context context) {String deviceId = null; try {TelephonyManager tm = (TelephonyManager) context .getSystemService (Context.TELEPHONY_SERVICE); if (Build.VERSION.SDK_INT > = Build.VERSION_CODES.Q) {deviceId = Settings.System.getString (context.getContentResolver (), Settings.Secure.ANDROID_ID) } else {/ / request old storage permission if (ActivityCompat.checkSelfPermission (context, Manifest.permission.READ_PHONE_STATE)! = PackageManager.PERMISSION_GRANTED) {/ / TODO: Consider calling / / ActivityCompat#requestPermissions / / here to request the missing permissions, and then overriding / / public void onRequestPermissionsResult (int requestCode, String [] permissions / / int [] grantResults) / / to handle the case where the user grants the permission. See the documentation / / for ActivityCompat#requestPermissions for more details. Return null;} deviceId = tm.getDeviceId ();} if (deviceId = = null | | ".equals (deviceId)) {return getLocalMacAddress (context);}} catch (Exception e) {e.printStackTrace (); if (deviceId = = null | |" .equals (deviceId)) {return getLocalMacAddress (context);}} return deviceId;}

Google officially announced that the phone will be restored to factory settings and Android ID will be reset.

If the user denies permission, the device identity will still not be obtained.

This is the end of the article on "how to replace IMEI with Android_id in Android". Thank you for reading! I believe you all have a certain understanding of the knowledge of "how to replace IMEI with Android_id in Android". If you want to learn more, you are welcome to follow the industry information channel.

Tags: Version knowledge content address method logo article value official mobile phone easy to operate article easy to understand more permissions users look industry equipment information Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Microsoft Shulou Information MariaDB vpn OPPO Reno