Android 安卓10 USB主机-Can';无法连接到设备,权限未授予(但应授予)
我一直在遵循这里的指导,以便连接到usb设备,使用Android手机作为主机 从下面的段落中,我相信只要我正确地为USB_设备_附加操作设置了意图过滤器,并为我的设备设置了过滤器-我应该已经拥有连接到它所需的所有权限Android 安卓10 USB主机-Can';无法连接到设备,权限未授予(但应授予),android,usb,android-10.0,Android,Usb,Android 10.0,我一直在遵循这里的指导,以便连接到usb设备,使用Android手机作为主机 从下面的段落中,我相信只要我正确地为USB_设备_附加操作设置了意图过滤器,并为我的设备设置了过滤器-我应该已经拥有连接到它所需的所有权限 Note: If your application uses an intent filter to discover USB devices as they're connected, it automatically receives permission if the use
Note: If your application uses an intent filter to discover USB devices as they're connected, it automatically receives permission if the user allows your application to handle the intent. If not, you must request permission explicitly in your application before connecting to the device.
我举一个简单的例子:
public class MainActivity extends Activity {
private final static String TAG = "USB_HOST_EXAMPLE";
UsbManager usbManager;
UsbDeviceConnection connection;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
usbManager = (UsbManager) getSystemService(Context.USB_SERVICE);
Intent intent = getIntent();
if (intent != null) {
UsbDevice device = (UsbDevice) intent.getParcelableExtra(UsbManager.EXTRA_DEVICE);
if (device != null) {
Log.w(TAG, "Started activty from intent filter, using device: " + device.getProductName());
connection = usbManager.openDevice(device);
}
}
}
}
当前行为:
我也尝试过枚举设备和请求权限,如前所述,但当我找到我的USB设备并转到请求权限时,调用时应显示的“弹出窗口”
usbManager.requestPermission(device, permissionIntent);
不显示,广播接收器返回
permission denied for device UsbDevice.....
我在安卓10上,在Pixel 2和Pixel 3a上也遇到过同样的问题(3a是植根的)。你有没有尝试过其他安卓版本?没有,不幸的是,我没有任何开发人员手机运行安卓10之前的版本。对不起,USB权限设置是什么意思?我已经看过了,但不知道有任何明显的usb许可。这方面运气好吗?你是怎么解决的?希望使用android 10绕过usb权限。
permission denied for device UsbDevice.....