运行脚本时收到错误消息“无法从静态上下文引用非静态方法getDeviceList()”-如何使此方法静态化?
private static String getUsbDeviceAddress(String selection) {
String address = selection;
if (android.os.Build.VERSION.SDK_INT > 21) {
HashMap<String, UsbDevice> deviceList = UsbManager.getDeviceList();
for (UsbDevice device : deviceList.values()) {
if (device != null) {
String dsn = device.getSerialNumber();
if ((dsn != null) && !dsn.isEmpty()) {
if (selection.equalsIgnoreCase(dsn)) {
address = device.getDeviceName();
break;
}
}
}
}
}
return address;
}
getDeviceList()方法不是静态的。您需要像]一样声明>
public static HashMap<String, UsbDevice> getDeviceList(){}