【函数】 | boolean isSupported() |
【说明】 | 是否支持蓝牙。 |
【返回】 | true或false。 |
【参数】 | 无 |
【示例】 |
alert(rexseeBluetooth.isSupported());
运行示例
|
【函数】 | boolean isEnabled() |
【说明】 | 蓝牙是否已经启动。 |
【返回】 | true或false。 |
【参数】 | 无 |
【示例】 |
alert(rexseeBluetooth.isEnabled());
运行示例
|
【函数】 | String getState() |
【说明】 | 读取当前蓝牙状态。 |
【返回】 | 当前蓝牙状态,"on"、"off"、"turning_on"、"turning_off"或"unknown"。 |
【参数】 | 无 |
【示例】 |
alert(rexseeBluetooth.getState());
运行示例
|
【函数】 | void enable() |
【说明】 | 询问用户并启动蓝牙。 |
【返回】 | 无 |
【参数】 | 无 |
【示例】 |
rexseeBluetooth.enable();
事件代码
运行示例
|
【函数】 | void forceEnable() |
【说明】 | 不询问用户,强制启动蓝牙。 |
【返回】 | true或false,表示函数是否成功执行,但是不代表启动成功,应使用onBluetoothStateChanged获取启动成功的通知。 |
【参数】 | 无 |
【示例】 |
rexseeBluetooth.startListenerForBroadcast();
事件代码
运行示例
alert(rexseeBluetooth.forceEnable()); |
【函数】 | void disable() |
【说明】 | 不询问用户,强制关闭蓝牙。 |
【返回】 | true或false,表示函数是否成功执行,但是不代表关闭成功,应使用onBluetoothStateChanged获取关闭成功的通知。 |
【参数】 | 无 |
【示例】 |
rexseeBluetooth.startListenerForBroadcast();
事件代码
运行示例
alert(rexseeBluetooth.disable()); |
【函数】 | String getAddress() |
【说明】 | 读取本机蓝牙地址,蓝牙地址是全球唯一的。 |
【返回】 | 本机蓝牙地址。 |
【参数】 | 无 |
【示例】 |
alert(rexseeBluetooth.getAddress());
运行示例
|
【函数】 | String getName() |
【说明】 | 读取本机蓝牙适配器当前使用的名称,该名称用于被其它设备方便地标识,注意,名称不是唯一的,只有地址是唯一的。 |
【返回】 | 本机蓝牙适配器当前使用的名称,可通过setName()修改。 |
【参数】 | 无 |
【示例】 |
alert(rexseeBluetooth.getName());
运行示例
|
【函数】 | boolean setName(String name) |
【说明】 | 设置本机蓝牙适配器当前使用的名称,该名称用于被其它设备方便地标识,注意,名称不是唯一的,只有地址是唯一的。 |
【返回】 | true或false。 |
【参数】 | name:名称。 |
【示例】 |
alert(rexseeBluetooth.setName('test'));
运行示例
alert(rexseeBluetooth.setName(rexseeBuild.getModel()));
运行示例
|
【函数】 | boolean isListeningToBroascast() |
【说明】 |
是否正在侦听广播事件,详细说明请参考蓝牙事件。.这些广播事件包括:
|
【返回】 | true或false。 |
【参数】 | 无 |
【示例】 |
alert(rexseeBluetooth.isListeningToBroascast());
运行示例
|
【函数】 | boolean startListenerForBroadcast() |
【说明】 | 开始侦听广播事件。 |
【返回】 | 无 |
【参数】 | true或false。 |
【示例】 |
rexseeBluetooth.startListenerForBroadcast();
运行示例
rexseeDialog.toast('Start listening.'); |
【函数】 | boolean stopListenerForBroadcast() |
【说明】 | 停止侦听广播事件。 |
【返回】 | 无 |
【参数】 | true或false。 |
【示例】 |
rexseeBluetooth.stopListenerForBroadcast();
运行示例
rexseeDialog.toast('Stop listening.'); |
【函数】 | String getScanMode() |
【说明】 | 读取当前的蓝牙扫描方式,可通过setDiscoverable()修改。 |
【返回】 | 当前的蓝牙扫描方式,"connectable"、"connectable_discoverable"或"none"。 |
【参数】 | 无 |
【示例】 |
alert(rexseeBluetooth.getScanMode());
运行示例
|
【函数】 | boolean isDiscoverable() |
【说明】 | 蓝牙是否允许被检测,即getScanMode()是否等于"connectable_discoverable"。 |
【返回】 | true或false。 |
【参数】 | 无 |
【示例】 |
alert(rexseeBluetooth.isDiscoverable());
运行示例
|
【函数】 | void setDiscoverable(int seconds) |
【说明】 | 询问用户并将扫描状态设为“connectable_discoverable”,即可被其它设备检测。 |
【返回】 | 无 |
【参数】 | seconds:可被检测的时间,秒数,最多300秒,默认为120秒;设为0秒可立即终止可检测的状态。 |
【示例】 |
rexseeBluetooth.setDiscoverable(300);
事件代码
运行示例
|
【函数】 | boolean isDiscovering() |
【说明】 | 蓝牙是否正在扫描其它设备。 |
【返回】 | true或false。 |
【参数】 | 无 |
【示例】 |
alert(rexseeBluetooth.isDiscovering());
运行示例
|
【函数】 | boolean startDiscovery() |
【说明】 | 开始扫描。 |
【返回】 | true或false,表示函数是否成功执行,使用onBluetoothDiscoveringStarted、onBluetoothDiscoveringFinished和onBluetoothDeviceFound获取扫描开始、扫描结束和发现新的远端设备的通知。 |
【参数】 | 无 |
【示例】 |
rexseeBluetooth.startListenerForBroadcast();
事件代码
运行示例
alert(rexseeBluetooth.startDiscovery()); |
【函数】 | boolean cancelDiscovery() |
【说明】 | 终止扫描。 |
【返回】 | true或false,表示函数是否成功执行,onBluetoothDiscoveringFinished获取扫描结束的通知。 |
【参数】 | 无 |
【示例】 |
rexseeBluetooth.startListenerForBroadcast();
事件代码
运行示例
alert(rexseeBluetooth.cancelDiscovery()); |
【函数】 | JsonObjectArray getCurrentDevices(String address) |
【说明】 | 获得当前所有远端蓝牙设备的信息(扫描后才能获得该信息)。 |
【返回】 | 返回值是一个JSON格式的字符串,是一个对象数组,数组每个元素是一个蓝牙设备的信息对象(参加getDeviceInformation(String address)),使用eval('('+json+')')可以将JSON字符串转换为JavaScript对象。 |
【参数】 | 无 |
【示例】 |
alert(rexseeBluetooth.getCurrentDevices());
运行示例
|
【函数】 | JsonObject getDeviceInformation(String address) |
【说明】 | 获得远端蓝牙设备的信息。 |
【返回】 |
返回值是一个JSON格式的字符串,使用eval('('+json+')')可以将JSON字符串转换为JavaScript对象。
{
|
【参数】 | 无 |
【示例】 | 参见事件onBluetoothDeviceFound(String address)等。 |
【函数】 | JsonObjectArray getBondedDevices(String address) |
【说明】 | 获得已绑定的所有远端蓝牙设备的信息。 |
【返回】 | 返回值是一个JSON格式的字符串,是一个对象数组,数组每个元素是一个蓝牙设备的信息对象(参加getDeviceInformation(String address)),使用eval('('+json+')')可以将JSON字符串转换为JavaScript对象。 |
【参数】 | 无 |
【示例】 |
alert(rexseeBluetooth.getBondedDevices());
运行示例
|
【函数】 | boolean createBond(String address) |
【说明】 | 和远端设备配对。 |
【返回】 | true或false,表示函数是否成功执行,使用onBluetoothDeviceBondStateChanged获取配对结果。 |
【参数】 | address:远端设备地址。 |
【示例】 |
alert(rexseeBluetooth.createBond(eval('('+rexseeBluetooth.getCurrentDevices()+')')[1].address));
代码
事件代码
运行示例
|
【函数】 | boolean removeBond(String address) |
【说明】 | 取消和远端设备的配对。 |
【返回】 | true或false,表示函数是否成功执行,使用onBluetoothDeviceBondStateChanged获取执行结果。 |
【参数】 | address:远端设备地址。 |
【示例】 | 代码 事件代码 运行示例 |
【函数】 | boolean isListeningToConnectRequest() |
【说明】 | 是否正在侦听远端设备的连接请求。 |
【返回】 | true或false。 |
【参数】 | 无 |
【示例】 |
alert(rexseeBluetooth.isListeningToConnectRequest());
运行示例
|
【函数】 | boolean startListenerForConnectRequest() |
【说明】 | 开始侦听远端设备的连接请求。 |
【返回】 | 是否成功开始侦听,侦听到连接请求时会触发事件onBluetoothReceivedConnectRequest。 |
【参数】 | 无 |
【示例】 |
alert(rexseeBluetooth.startListenerForConnectRequest());
事件代码
运行示例
|
【函数】 | boolean stopListenerForConnectRequest() |
【说明】 | 停止侦听远端设备的连接请求。 |
【返回】 | 是否成功停止开始侦听。 |
【参数】 | 无 |
【示例】 |
alert(rexseeBluetooth.stopListenerForConnectRequest());
运行示例
|
【函数】 | void accept() |
【说明】 | 接受侦听到的远端设备的连接请求,应在事件onBluetoothReceivedConnectRequest中调用。 |
【返回】 | 无 |
【参数】 | 无 |
【示例】 | 无 |
【函数】 | void deny() |
【说明】 | 拒绝侦听到的远端设备的连接请求,应在事件onBluetoothReceivedConnectRequest中调用。 |
【返回】 | 无 |
【参数】 | 无 |
【示例】 | 无 |
【函数】 | void connect(String address) |
【说明】 | 和远端设备建立连接,使用onBluetoothDeviceConnectStateChanged获取执行结果。连接成功后,如果接收到了远端发送的数据,会触发事件onBluetoothDataRead,如果向远端设备写入数据,会触发事件onBluetoothDataWrite。 |
【返回】 | 无 |
【参数】 | address:远端设备地址。 |
【示例】 | 代码 事件代码 运行示例 |
【函数】 | void disconnect() |
【说明】 | 断开和任何远端设备的连接,使用onBluetoothDeviceConnectStateChanged获取执行结果。 |
【返回】 | 无 |
【参数】 | 无 |
【示例】 |
rexseeBluetooth.disconnect();
事件代码
运行示例
|
【函数】 | boolean isConnected() |
【说明】 | 判断是否和远端设备建立了连接,如果返回为true,可以用getCurrentDevice()函数获取当前正在操作的远端设备的信息。 |
【返回】 | true或false。 |
【参数】 | 无 |
【示例】 |
alert(rexseeBluetooth.isConnected());
运行示例
|
【函数】 | String getConnectState() |
【说明】 | 当前连接状态,"connecting"、"connected"或"none",如果不为"none",可以用getCurrentDevice()函数获取当前正在操作的远端设备的信息。 |
【返回】 | "connecting"、"connected"或者"none"。 |
【参数】 | 无 |
【示例】 |
alert(rexseeBluetooth.getConnectState());
运行示例
|
【函数】 | String getPreviousConnectState() |
【说明】 | 在onBluetoothDeviceConnectStateChanged事件中判断状态变化之前的状态。 |
【返回】 | "connecting"、"connected"或者"none"。 |
【参数】 | 无 |
【示例】 |
alert(rexseeBluetooth.getPreviousConnectState());
运行示例
|
【函数】 | JsonObject getCurrentDevice() |
【说明】 | 当前正在操作的远端设备的信息。 |
【返回】 | JSON对象字符串,格式和getDeviceInformation(String address)函数的返回值相同。 |
【参数】 | 无 |
【示例】 |
alert(rexseeBluetooth.getCurrentDevice());
运行示例
|
【函数】 | void write(String str, String encoding) |
【说明】 | 向远端设备发送字符串,会触发事件onBluetoothDataWrite。 |
【返回】 | 无 |
【参数】 | str:要发送的字符串。 encoding:远端设备使用的字符编码,"utf-8"、"GBK"等。 |
【示例】 |
rexseeBluetooth.write('This is a test!','UTF-8');
运行示例
|
【函数】 | void writeASCII(String ascii) |
【说明】 | 向远端设备发送ASCII编码,会触发事件onBluetoothDataWrite。 |
【返回】 | 无 |
【参数】 | ascii:用","隔开的ASCII编码,例如字符"LF"的ASCII值为10,对于ESC/POS 兼容指令的打印机而言,代表打印并换行,可以调用writeASCII('10');而ESC和@的ASCII编码分别为27和64,对于ESC/POS 兼容指令的打印机而言,代表复位打印机,可以调用writeASCII('27,64')。 |
【示例】 |
rexseeBluetooth.writeASCII('10');
运行示例
|
【函数】 | JsonArray getSupportedDeviceClasses() |
【说明】 | 所有已知的蓝牙类型(包含主类型和次类型)。 |
【返回】 | 返回值是一个JSON格式的字符串,是一个数组,每个元素都是字符串,代表一个类型,使用eval('('+json+')')将JSON字符串转换为JavaScript数组。 |
【参数】 | 无 |
【示例】 |
alert(rexseeBluetooth.getSupportedDeviceClasses());
运行示例
|
【函数】 | JsonArray getSupportedDeviceMajorClasses() |
【说明】 | 所有已知的蓝牙类型(主类型)。 |
【返回】 | 返回值是一个JSON格式的字符串,是一个数组,每个元素都是字符串,代表一个主类型,使用eval('('+json+')')可以将JSON字符串转换为JavaScript数组。 |
【参数】 | 无 |
【示例】 |
alert(rexseeBluetooth.getSupportedDeviceMajorClasses());
运行示例
|
【函数】 | JsonArray getSupportServiceClasses() |
【说明】 | 所有已知的蓝牙服务类型。 |
【返回】 | 返回值是一个JSON格式的字符串,是一个数组,每个元素都是字符串,代表一个服务类型,使用eval('('+json+')')可以将JSON字符串转换为JavaScript数组。 |
【参数】 | 无 |
【示例】 |
alert(rexseeBluetooth.getSupportServiceClasses());
运行示例
|