我正在尝试连接到安卓手机使用WebUSB与USB调试关闭。但是它会返回一个错误DOMException Acces denied。基本上,我希望我的PC作为USB客户端(如键盘或任何usb设备)连接到Android手机。
但是,其它USB设备(如USB音频设备)未显示任何错误。我在device.open()上收到访问错误
let device = null
let configValue = 0
let interfaceValue = 0
const connect = async() => {
try {
device = await navigator.usb.requestDevice({
filters : [{}]
});
await device.open()
// if(device.configurations.length > 0){
// configValue = device.configuration.configurationValue
// interfaceValue = device.configuration.interfaces[0].interfaceNumber
// await device.selectConfiguration(configValue)
// await device.claimInterface(interfaceValue)
// }
console.log(device);
} catch (error) {
console.log(error);
}
}发布于 2021-09-13 18:43:07
当Android设备没有启用USB调试时,它不会提供Windows允许用户空间应用程序(如您的web浏览器)声明的USB接口。这就是为什么你会得到“访问被拒绝”的错误。
听起来你想要做的是让你的电脑充当USB外设,这样手机就可以作为USB主机连接到电脑上。大多数台式机USB控制器都不支持此模式,WebUSB应用编程接口也不支持此模式。
https://stackoverflow.com/questions/69161729
复制相似问题