安卓原生调用
本插件可以使用安卓原生开发调用,具体方法如下
1.下载apk插件
2.放到项目asset文件夹下
3.AndroidManifest.xml文件中添加权限
<uses-permission android:name="android.permission.INTERNET" ></uses>
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" ></uses>
<uses-permission android:name="android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS" ></uses>
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"></uses>
<uses-permission android:name="android.permission.INTERNAL_SYSTEM_WINDOW" ></uses>
<!-- 声明权限 -->
<uses-permission android:name="android.permission.BIND_WALLPAPER" ></uses>
<uses-feature android:name="android.hardware.usb.accessory" ></uses>
<uses-permission android:name="android.permission.USB_PERMISSION" ></uses> <!-- 添加USB权限 -->
<uses-feature android:name="android.hardware.usb.host" ></uses>
<!-- Request legacy Bluetooth permissions on older devices. -->
<uses-permission android:name="android.permission.BLUETOOTH" ></uses>
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" ></uses>
<!-- Needed only if your app looks for Bluetooth devices.
You must add an attribute to this permission, or declare the
ACCESS_FINE_LOCATION permission, depending on the results when you
check location usage in your app. -->
<uses-permission android:name="android.permission.BLUETOOTH_CONNECT" ></uses>
<uses-permission android:name="android.permission.BLUETOOTH_CONNECT" ></uses>
<uses-permission android:name="android.permission.BLUETOOTH_SCAN" ></uses>
<!-- Needed only if your app makes the device discoverable to Bluetooth
devices. -->
<uses-permission android:name="android.permission.BLUETOOTH_ADVERTISE" ></uses>
<!-- Needed only if your app communicates with already-paired Bluetooth
devices. -->
<uses-permission android:name="android.permission.BLUETOOTH_CONNECT" ></uses>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" ></uses>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" ></uses>
<uses-permission android:name="android.permission.BLUETOOTH_SCAN" ></uses>
4.把这个xml文件添加到xml文件夹中accessory_filter.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<usb-accessory manufacturer="aiwork" model="hid" version="2.0" />
</resources>
5.在AndroidManifest.xml 中 mainActivity中添加以下代码
<activity
android:name=".MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.hardware.usb.action.USB_ACCESSORY_ATTACHED" />
</intent-filter>
<meta-data
android:name="android.hardware.usb.action.USB_ACCESSORY_ATTACHED"
android:resource="@xml/accessory_filter" />
</activity> <!-- 注册USB设备连接和断开的广播接收器 -->
上次更新: 2024/11/05, 13:43:57