Advertisement
NubeColectiva

Obtener IMEI Android 10 Q (Java)

Mar 12th, 2021
956
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.22 KB | None | 0 0
  1. public static String getIMEIDeviceId(Context context) {
  2.  
  3.         String deviceId;
  4.  
  5.         if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q)
  6.         {
  7.             deviceId = Settings.Secure.getString(context.getContentResolver(), Settings.Secure.ANDROID_ID);
  8.         } else {
  9.             final TelephonyManager mTelephony = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
  10.             if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
  11.                 if (context.checkSelfPermission(Manifest.permission.READ_PHONE_STATE) != PackageManager.PERMISSION_GRANTED) {
  12.                     return "";
  13.                 }
  14.             }
  15.             assert mTelephony != null;
  16.             if (mTelephony.getDeviceId() != null)
  17.             {
  18.                 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)
  19.                 {
  20.                     deviceId = mTelephony.getImei();
  21.                 }else {
  22.                     deviceId = mTelephony.getDeviceId();
  23.                 }
  24.             } else {
  25.                 deviceId = Settings.Secure.getString(context.getContentResolver(), Settings.Secure.ANDROID_ID);
  26.             }
  27.         }
  28.         Log.d("deviceId", deviceId);
  29.         return deviceId;
  30.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement