大网站建设,浏览器有些网页打不开是什么原因,4399老版网页,网易企业邮箱登录入口手机网页版目录 一、前提
1. unity打包android后#xff0c;链接USB摄像头#xff0c;需要USB权限。
二、流程
1.Unity导出android工程#xff0c;Player配置如图#xff1a;
2.导出android工程 3.在android工程中找到AndroidManifest.xml加入usb权限相关
?xml version链接USB摄像头需要USB权限。
二、流程
1.Unity导出android工程Player配置如图
2.导出android工程 3.在android工程中找到AndroidManifest.xml加入usb权限相关
?xml version1.0 encodingutf-8?
manifest xmlns:androidhttp://schemas.android.com/apk/res/androidxmlns:toolshttp://schemas.android.com/toolsapplication android:extractNativeLibstrueactivity android:namecom.unity3d.player.UnityPlayerActivity android:themestyle/UnityThemeSelector android:screenOrientationfullSensor android:launchModesingleTask android:configChangesmcc|mnc|locale|touchscreen|keyboard|keyboardHidden|navigation|orientation|screenLayout|uiMode|screenSize|smallestScreenSize|fontScale|layoutDirection|density android:resizeableActivityfalse android:hardwareAcceleratedfalseintent-filteraction android:nameandroid.intent.action.MAIN /category android:nameandroid.intent.category.LAUNCHER ///此处action android:nameandroid.hardware.usb.action.USB_DEVICE_ATTACHED //intent-filtermeta-data android:nameunityplayer.UnityActivity android:valuetrue /meta-data android:nameandroid.notch_support android:valuetrue //activitymeta-data android:nameunity.splash-mode android:value0 /meta-data android:nameunity.splash-enable android:valueTrue /meta-data android:nameunity.launch-fullscreen android:valueTrue /meta-data android:nameunity.allow-resizable-window android:valueFalse /meta-data android:namenotch.config android:valueportrait|landscape //applicationuses-feature android:glEsVersion0x00020000 /uses-permission android:nameandroid.permission.INTERNET /uses-permission android:nameandroid.permission.CAMERA ///此处uses-feature android:nameandroid.hardware.usb.host ///此处uses-permission android:nameandroid.permission.USB_PERMISSION /uses-feature android:nameandroid.hardware.camera android:requiredfalse /uses-feature android:nameandroid.hardware.camera.autofocus android:requiredfalse /uses-feature android:nameandroid.hardware.camera.front android:requiredfalse /uses-feature android:nameandroid.hardware.touchscreen android:requiredfalse /uses-feature android:nameandroid.hardware.touchscreen.multitouch android:requiredfalse /uses-feature android:nameandroid.hardware.touchscreen.multitouch.distinct android:requiredfalse /
/manifest
备注主要三行如下
action android:nameandroid.hardware.usb.action.USB_DEVICE_ATTACHED /
uses-feature android:nameandroid.hardware.usb.host /
uses-permission android:nameandroid.permission.USB_PERMISSION /
4.找到UnityPlayerActivity.java在unity启动onResume方法里面新增打开USB权限设置
private static final String TAG unity;private static final String ACTION_USB_PERMISSION com.android.usb.USB_PERMISSION;private UsbManager usbManager;private UsbDeviceConnection connection;private PendingIntent permissionIntent;private boolean permissionGranted false;private BroadcastReceiver usbReceiver new BroadcastReceiver() {Overridepublic void onReceive(Context context, Intent intent) {String action intent.getAction();Log.d(TAG, USB设备连接有变化,链接到:action);if (ACTION_USB_PERMISSION.equals(action)) {synchronized (this) {unregisterReceiver(usbReceiver);UsbDevice usbDevice intent.getParcelableExtra(UsbManager.EXTRA_DEVICE);if (intent.getBooleanExtra(UsbManager.EXTRA_PERMISSION_GRANTED, false)) {if (usbDevice ! null) {// 用户已授权访问USB设备connectUsbDevice(usbDevice);}} else {Log.d(TAG, 用户未授权访问USB设备);
// requestPermission(usbDevice);}}}}};// Resume UnityOverride protected void onResume(){super.onResume();if (MultiWindowSupport.getAllowResizableWindow(this))return;mUnityPlayer.resume();openUsbDevice();}private void openUsbDevice(){// //获取注册usbusbManager (UsbManager) getSystemService(Context.USB_SERVICE);IntentFilter filter new IntentFilter(ACTION_USB_PERMISSION);// 获取已连接的USB设备列表HashMapString, UsbDevice deviceList usbManager.getDeviceList();IteratorUsbDevice deviceIterator deviceList.values().iterator();if (deviceIterator.hasNext()) {UsbDevice device deviceIterator.next();permissionIntent PendingIntent.getBroadcast(this, 0, new Intent(ACTION_USB_PERMISSION), 0);filter.addAction(UsbManager.ACTION_USB_DEVICE_ATTACHED);filter.addAction(UsbManager.ACTION_USB_DEVICE_DETACHED);Log.e(TAG, getDeviceList: device.getVendorId()device.getProductId());///注册广播registerReceiver(usbReceiver, filter);usbManager.requestPermission(device, permissionIntent);} else {Log.d(TAG, 没有找到已连接的USB设备);Toast.makeText(this, 没有找到已连接的USB设备, Toast.LENGTH_SHORT).show();}}private void connectUsbDevice(UsbDevice usbDevice) {if (usbDevice null) {return;}connection usbManager.openDevice(usbDevice);if (connection ! null) {// 在此处执行USB通信操作Log.d(TAG, USB设备已连接);Toast.makeText(this, USB设备已连接, Toast.LENGTH_SHORT).show();} else {Log.d(TAG, 无法打开USB设备连接);Toast.makeText(this, 无法打开USB设备连接, Toast.LENGTH_SHORT).show();}}
注意应用需要打开摄像机权限