zoukankan      html  css  js  c++  java
  • Unity 蓝牙插件

    1、新建一个Unity5.6.2f1工程,导入正版Bluetooth LE for iOS tvOS and Android.unitypackage
    2、用JD-GUI反编译工具查看unityandroidbluetoothlelib.jar
    3、将反编译的代码拷贝出来,建立对应的文件目录,
    4、在Eclipse中建立空工程,将代码文件放进去。
    5、修改AndroidManifest.xml,添加蓝牙权限
    <uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/>
    <uses-permission android:name="android.permission.BLUETOOTH"/>
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
    <uses-feature android:name="android.hardware.bluetooth_le" android:required="false"/>
    6、将unity-classes.jar文件添加到libs目录下.这个jar文件可以从Unity导出一个Android工程中找到
    7、修改其中的3处错误
    (A)注释的这个
    //import android.bluetooth.le.ScanSettings.Builder;
    (B)
    private UUID getFullBluetoothLEUUID(String uuidString)函数中UUID uuid;重定义了
    (C)
    public class AdRecordList类中的
    this.Records.add(new UnityBluetoothLE.AdRecord(UnityBluetoothLE.this, length, type, data));
    改为this.Records.add(new UnityBluetoothLE.AdRecord(length, type, data));

    +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    +++++++++重点来了,LEKE山寨机Q9自带的didoOS6.5系统不能执行蓝牙扫描功能函数+++++++
    +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    我要做的就是修好这个BUG!!!

    之所以可以确定可以修好这个BUG,是因为有一款通过蓝牙控制机器人的APP装在这台山寨机上可以进行蓝牙通信

    经过几天的缜密调试测试,发现那款APP也只能连接已经配对好的机器人蓝牙!!!
    找到突破口!既然这货不能通过程序API扫描周围蓝牙设备,那就用它自带的系统蓝牙扫描(自带的系统蓝牙扫描还是能用的)
    在程序中获取已经配对的蓝牙设备。
    GOOOOOOOD!!
    网上找到相关代码碎片,拿过来测试,通过!!
    在private void api21Scan(List<UUID> uuids)开头添加以下代码:
    //得到所有已配对的蓝牙适配器对象
    Set<BluetoothDevice> devices = mBluetoothAdapter.getBondedDevices();
    if(devices.size()>0){
    for(Iterator iterator = devices.iterator();iterator.hasNext();){
    BluetoothDevice bluetoothDevice = (BluetoothDevice) iterator.next();
    //Toast.makeText(mContext, "AA>>>"+bluetoothDevice.getAddress(), Toast.LENGTH_SHORT).show();
    // 给Unity发送过去
    UnityBluetoothLE.this.sendDiscoveredDevice(bluetoothDevice, 0, null);
    }
    }


    Eclipse中打包jar步骤:
    项目名右键-选择Properties-勾选Is Library-Apply-OK
    项目名右键-Build Project,将会在bin目录下生成一个.jar文件

    最后将工程打包成一个jar文件,替换掉Unity工程中的unityandroidbluetoothlelib.jar

  • 相关阅读:
    storm环境搭建
    环境变量
    vmware tools安装及使用其实现与宿主机共享文件夹
    关于mysql中的count()函数
    centos7配置jdk8
    linux常用命令(随时更新中)
    ES中对索引的相关操作
    linux centos7下源码 tar安装mysql5.7.23(5.7以上均可试用)
    安装linux虚拟机配置静态ip(桥接模式,外部机器能够访问)
    安装linux虚拟机配置静态ip(NAT模式)
  • 原文地址:https://www.cnblogs.com/coolbear/p/7551847.html
Copyright © 2011-2022 走看看