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

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是否能开发蓝牙打印功能?

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值