Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-core/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 安卓10 USB主机-Can';无法连接到设备,权限未授予(但应授予)_Android_Usb_Android 10.0 - Fatal编程技术网

Android 安卓10 USB主机-Can';无法连接到设备,权限未授予(但应授予)

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

我一直在遵循这里的指导,以便连接到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 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设备
  • 弹出询问我是否希望打开应用程序以使用此USB设备。(因此我的意图过滤器必须正常工作
  • 应用程序打开
  • 应用程序将连接到设备
  • 应用程序无法连接,响应时出现以下异常:

  • 我也尝试过枚举设备和请求权限,如前所述,但当我找到我的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.....