Java Code Examples for android.os.Build#getSerial()

The following examples show how to use android.os.Build#getSerial() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AndroidDeviceIMEIUtil.java    From CacheEmulatorChecker with Apache License 2.0 6 votes vote down vote up
@SuppressLint("MissingPermission")
public static String getSerialno() {
    String serialno = "";
    try {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
            serialno = Build.getSerial();
        } else {
            serialno = PropertiesGet.getString("ro.serialno");
            if (TextUtils.isEmpty(serialno)) {
                serialno = Build.SERIAL;
            }
        }
    } catch (Exception e) {
    }
    return serialno;
}
 
Example 2
Source File: RNDeviceModule.java    From react-native-device-info with MIT License 6 votes vote down vote up
@SuppressLint({"HardwareIds", "MissingPermission"})
@ReactMethod(isBlockingSynchronousMethod = true)
public String getSerialNumberSync() {
  try {
    if (Build.VERSION.SDK_INT >= 26) {
      if (getReactApplicationContext().checkCallingOrSelfPermission(Manifest.permission.READ_PHONE_STATE) == PackageManager.PERMISSION_GRANTED) {
        return Build.getSerial();
      }
    }
  } catch (Exception e) {
    // This is almost always a PermissionException. We will log it but return unknown
    System.err.println("getSerialNumber failed, it probably should not be used: " + e.getMessage());
  }

  return "unknown";
}
 
Example 3
Source File: PhoneUtils.java    From DevUtils with Apache License 2.0 5 votes vote down vote up
/**
 * 获取设备序列号
 * @return 设备序列号
 */
@RequiresPermission(android.Manifest.permission.READ_PHONE_STATE)
public static String getSerialNumber() {
    try {
        return Build.VERSION.SDK_INT >= Build.VERSION_CODES.O ? Build.getSerial() : Build.SERIAL;
    } catch (Exception e) {
        LogPrintUtils.eTag(TAG, e, "getSerialNumber");
    }
    return null;
}
 
Example 4
Source File: PhoneIdHelper.java    From MobileInfo with Apache License 2.0 5 votes vote down vote up
/**
 * 返回自己生产的唯一表示
 * @return
 */
@SuppressLint({"MissingPermission", "HardwareIds"})
public static String getUniqueID() {
    // If all else fails, if the user does have lower than API 9 (lower
    // than Gingerbread), has reset their phone or 'Secure.ANDROID_ID'
    // returns 'null', then simply the ID returned will be solely based
    // off their Android device information. This is where the collisions
    // can happen.
    // Thanks http://www.pocketmagic.net/?p=1662!
    // Try not to use DISPLAY, HOST or ID - these items could change.
    // If there are collisions, there will be overlapping data
    String m_szDevIDShort = "35" +
            (Build.BOARD.length() % 10)
            + (Build.BRAND.length() % 10)
            + (Build.CPU_ABI.length() % 10)
            + (Build.DEVICE.length() % 10)
            + (Build.MANUFACTURER.length() % 10)
            + (Build.MODEL.length() % 10)
            + (Build.PRODUCT.length() % 10);

    // Thanks to @Roman SL!
    // http://stackoverflow.com/a/4789483/950427
    // Only devices with API >= 9 have android.os.Build.SERIAL
    // http://developer.android.com/reference/android/os/Build.html#SERIAL
    // If a user upgrades software or roots their phone, there will be a duplicate entry
    String serial = "serial";
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        try {
            serial=Build.getSerial();
        } catch (Exception e) {
        }
    } else {
        serial=Build.SERIAL;
    }
    // Thanks @Joe!
    // http://stackoverflow.com/a/2853253/950427
    // Finally, combine the values we have found by using the UUID class to create a unique identifier
    return new UUID(m_szDevIDShort.hashCode(), serial.hashCode()).toString();
}
 
Example 5
Source File: PhoneUtils.java    From AndroidUtilCode with Apache License 2.0 5 votes vote down vote up
/**
 * Return the serial of device.
 *
 * @return the serial of device
 */
@SuppressLint("HardwareIds")
@RequiresPermission(READ_PHONE_STATE)
public static String getSerial() {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
        try {
            return Build.getSerial();
        } catch (SecurityException e) {
            e.printStackTrace();
            return "";
        }
    }
    return Build.VERSION.SDK_INT >= Build.VERSION_CODES.O ? Build.getSerial() : Build.SERIAL;
}
 
Example 6
Source File: EasyDeviceMod.java    From easydeviceinfo with Apache License 2.0 5 votes vote down vote up
/**
 * Gets serial.
 *
 * @return the serial
 */
@SuppressLint("HardwareIds")
public final String getSerial() {
  String result = null;
  if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) {
    result = Build.SERIAL;
  } else {
    if (PermissionUtil.hasPermission(context, Manifest.permission.READ_PHONE_STATE)) {
      result = Build.getSerial();
    }
  }
  return CheckValidityUtil.checkValidData(result);
}
 
Example 7
Source File: DeviceUtils.java    From Box with Apache License 2.0 4 votes vote down vote up
@SuppressLint("MissingPermission")
@RequiresPermission(READ_PHONE_STATE)
public static String getSN() {
    return Build.VERSION.SDK_INT >= Build.VERSION_CODES.O ? Build.getSerial() : Build.SERIAL;
}
 
Example 8
Source File: DeviceUtils.java    From Android-utils with Apache License 2.0 4 votes vote down vote up
@SuppressLint("HardwareIds")
@RequiresPermission(READ_PHONE_STATE)
public static String getSerial() {
    return Build.VERSION.SDK_INT >= Build.VERSION_CODES.O ? Build.getSerial() : Build.SERIAL;
}
 
Example 9
Source File: DeviceUtils.java    From Box with Apache License 2.0 4 votes vote down vote up
@SuppressLint("MissingPermission")
@RequiresPermission(READ_PHONE_STATE)
public static String getSN() {
    return Build.VERSION.SDK_INT >= Build.VERSION_CODES.O ? Build.getSerial() : Build.SERIAL;
}
 
Example 10
Source File: DeviceUtil.java    From BaseProject with MIT License 4 votes vote down vote up
/**
 * 返回序列号 (Android 2.3以上可以使用此方法)
 */
public String getSerialNumber() {
    String serialNumber = Build.VERSION.SDK_INT >= Build.VERSION_CODES.O ? Build.getSerial() : Build.SERIAL;
    return TextUtils.isEmpty(serialNumber) ? "" : serialNumber;
}