在Android 9之前,我可以通过root,系统化我的应用程序并使用下一个USB类来绕过Android USB主机权限确认对话框 https://dev59.com/7WYr5IYBdhLWcg3wYZKD#15378118 https://dev59.com/7WYr5IYBdhLWcg3wYZKD#19681849。但是对于最新的Android版本-9,它不起作用。它会抛出
有没有办法让它在Android 9上运行?
java.lang.NoSuchMethodError: No interface method grantDevicePermission(Landroid/hardware/usb/UsbDevice;I)V in class Landroid/hardware/usb/IUsbManager; or its super classes (declaration of 'android.hardware.usb.IUsbManager' appears in /system/framework/framework.jar)
异常。fun setUsbPermissionRoot(device: UsbDevice) : Boolean {
if (BuildConfig.DEBUG) Log.i(TAG, "trying set permission")
try {
val pm = App.context.packageManager
val ai = pm.getApplicationInfo(App.context.packageName, 0)
ai?.let {
val b = ServiceManager.getService(Context.USB_SERVICE)
val service = IUsbManager.Stub.asInterface(b)
service.grantDevicePermission(device, it.uid)
try {
service.setDevicePackage(device, App.context.packageName, it.uid)
} catch (e: Exception) {
e.printStackTrace()
}
if (BuildConfig.DEBUG) Log.i(TAG, "permission was set usb device")
return true
}
} catch (e: PackageManager.NameNotFoundException) {
if (BuildConfig.DEBUG) e.printStackTrace()
} catch (e: RemoteException) {
if (BuildConfig.DEBUG) e.printStackTrace()
}
return false
}
有没有办法让它在Android 9上运行?