fwyc
fwyc
  • 发布:2019-03-13 12:54
  • 更新:2019-03-15 11:34
  • 阅读:84

Bluetooth模块为什么demo示例无法运行

分类:HBuilder

我使用的是demo代码,但是总是报错 ,这是没什么呢?(小白一枚,求指导)
09:08:40.734 Uncaught TypeError: Cannot read property 'openBluetoothAdapter' of undefined at index.html:14
09:08:44.703 Uncaught TypeError: Cannot read property 'getBluetoothAdapterState' of undefined at index.html:25
09:08:45.516 Uncaught TypeError: Cannot read property 'closeBluetoothAdapter' of undefined at index.html:36
09:08:46.828 Uncaught TypeError: Cannot read property 'openBluetoothAdapter' of undefined at index.html:14
代码如下:

<!DOCTYPE html>  
<html>  
    <head>  
    <meta charset="utf-8">  
    <title>Bluetooth Example</title>  
    <script type="text/javascript" >  
// 扩展API加载完毕后调用onPlusReady回调函数   
document.addEventListener('plusready', onPlusReady, false);  
// 扩展API加载完毕,现在可以正常调用扩展API  
function onPlusReady(){  
}  
// 打开蓝牙模块  
function openBluetoothAdapter(){  
    plus.Bluetooth.openBluetoothAdapter({  
        success:function(e){  
            console.log('open success: '+JSON.stringify(e));  
        },  
        fail:function(e){  
            console.log('open failed: '+JSON.stringify(e));  
        }  
    });  
}  
// 获取蓝牙状态  
function getBluetoothState(){  
    plus.Bluetooth.getBluetoothAdapterState({  
        success:function(e){  
            console.log('state success: '+JSON.stringify(e));  
        },  
        fail:function(e){  
            console.log('state failed: '+JSON.stringify(e));  
        }  
    });  
}  
// 关闭蓝牙模块  
function closeBluetoothAdapter(){  
    plus.Bluetooth.closeBluetoothAdapter({  
        success:function(e){                                              
            console.log('close success: '+JSON.stringify(e));  
        },  
        fail:function(e){  
            console.log('close failed: '+JSON.stringify(e));  
        }  
    });  
}  

    </script>  
    </head>  
    <body >  
        <button onclick="openBluetoothAdapter()">打开蓝牙模块</button>  
        <br/>  
        <button onclick="getBluetoothState()">获取蓝牙状态</button>  
        <br/>  
        <button onclick="closeBluetoothAdapter()">关闭蓝牙模块</button>  
    </body>  
</html>  
2019-03-13 12:54 分享
已邀请:
1044800346@qq.com

1044800346@qq.com

小老弟,我也是这种情况

要回复问题请先登录注册