对于不提供serialNumber的设备,可以尝试使用其他设备属性来唯一标识设备,例如设备的IMEI或MAC地址。下面是一个使用IMEI来标识devicename的示例代码:
private static String getDeviceName(String imei) {
String name = "Unknown";
DeviceNameWithImei device = new DeviceNameWithImei(imei);
name = device.load().getName();
return name;
}
class DeviceNameWithImei extends AndroidManagementClient {
private final String imei;
public DeviceNameWithImei(String imei) {
super();
this.imei = imei;
}
@Override
protected Device loadDevice(String name) {
Device device = null;
List devices = listDevices();
for (Device d : devices) {
if (d.getDeviceSettings().getDeviceIdentifier().getImei().equals(imei)) {
device = d;
break;
}
}
if (device == null) {
Log.e(TAG, "Device with IMEI: " + imei + " not found");
}
return device;
}
}