通过游戏控制器
我测试通过官方文档方式检查设备是无法获取到相关设备的
val deviceIds = InputDevice.getDeviceIds()
deviceIds.forEach { it->
run {
InputDevice.getDevice(it)?.let { device ->
run {
Log.e("USB", "设备ID:${device.id} , 设备vid:${device.vendorId} , 设备pid:${device.productId}")
}
}
}
}
这里通过插拔设备打印的设备信息列表都是一致的。且没有弹窗申请。
通过USB设备获取
通过Steam Link 观察到它的连接方式是用USB Host模式 可以参考官方文档
通过Demo的通过USB设备获取按钮可以观察到能在插拔USB设备的情况下打印不同的列表
usbManager = getSystemService(USB_SERVICE) as UsbManager
usbManager.deviceList?.forEach { it ->
run {
Log.d("USB", "设备ID:${it.value.deviceName} , 设备vid:${it.value.vendorId} , 设备pid:${it.value.productId}")
sb.append("设备ID:${it.value.deviceName} , 设备vid:${it.value.vendorId} , 设备pid:${it.value.productId}\n")
if (it.value.productId == pid && it.value.vendorId == vid) {
requestPermission(it.value)
}
}
}
fun requestPermission(device: UsbDevice) {
val permissionIntent = PendingIntent.getBroadcast(
this,
0,
Intent(ACTION_USB_PERMISSION),
PendingIntent.FLAG_IMMUTABLE
)
if (usbManager.hasPermission(device)) {
connectUsb(device)
} else {
usbManager.requestPermission(device, permissionIntent)
}
}
总结
建议新增使用USB方式获取手柄信息,我估计SteamLink能响应我之前反馈的PS手柄的PS按键也是采用该方案。
Description
Languages
Kotlin
100%
