小虎
小虎
  • 发布:2015-07-02 13:00
  • 更新:2015-07-17 15:57
  • 阅读:2753

获取已配对的蓝牙问题,接口返回的数据好像有问题?

分类:Native.js
mui.plusReady(function() {  
    switch (plus.os.name) {  
        case "Android":  
            main = plus.android.runtimeMainActivity();  
            BluetoothAdapter = plus.android.importClass("android.bluetooth.BluetoothAdapter"); //本机蓝牙适配器  
            BluetoothDevice = plus.android.importClass("android.bluetooth.BluetoothDevice");  
            BluetoothSocket = plus.android.importClass("android.bluetooth.BluetoothSocket");  
            BluetoothReceiver = plus.android.importClass("android.bluetooth.BluetoothReceiver");  
            Intent = plus.android.importClass("android.content.Intent");  
            IntentFilter = plus.android.importClass("android.content.IntentFilter");  
            BAdapter = BluetoothAdapter.getDefaultAdapter(); //获得本机蓝牙适配器  
            /*检查是否支持蓝牙*/  
            if (BAdapter == null) {  
                mui.toast("本地蓝牙设备驱动异常");  
                return false;  
            } else {  
                /*检查蓝牙打开状态*/  
                if (!BAdapter.isEnabled()) {  
                    var intent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE); //打开蓝牙  
                    BAdapter.enable();  
                    console.log(BAdapter.getAddress());  
                    console.log(BAdapter.getName());  
                }  
                /**  
                 * 检查蓝牙扫描模式  
                 * BAdapter.getScanMode() 获取蓝牙扫描模式  
                 * BluetoothAdapter.SCAN_MODE_CONNECTABLE_DISCOVERABLE 值为23, 查询扫描和页面扫描都有效  
                 */  
                if (BAdapter.getScanMode() != BluetoothAdapter.SCAN_MODE_CONNECTABLE_DISCOVERABLE) {  
                    var discoverableIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE); //打开蓝牙搜索  
                    discoverableIntent.putExtra(BluetoothAdapter.EXTRA_DISCOVERABLE_DURATION, 300); //设置扫描时间(最多300秒)  
                    main.startActivity(discoverableIntent);  
                }  
                /*获取已配对设备*/  
                var devices = BAdapter.getBondedDevices();  
                plus.android.importClass(devices);  
                console.log(devices);  
                var devices_len = devices.size();  
                for (var i = 0; i < devices_len; i++) {  
                    console.log(devices.get(i));  
                }  
            }  
            break;  
        case "iOS":  
            break;  
        default:  
            break;  
    }  
});

devices.get(i)报错,里面没有get方法。对JAVA不熟悉,官方的麻烦帮助看下。

另一个问题是Native.js是否能开发蓝牙打印功能?

2015-07-02 13:00 负责人:无 分享
已邀请:
小虎

小虎 (作者)

问题无人回复,官方没人气啊

  • 赵梦欢

    哎,官方支持力度不够啊,我给他们私发消息,都没人鸟

    2015-07-07 00:04

Jayming1024

Jayming1024

http://ask.dcloud.net.cn/question/7676

该问题目前已经被锁定, 无法添加新回复