搜索蓝牙速度太慢,有时候搜不到蓝牙,哪位大神能帮忙解决一下,有偿的,代码如下:
main = plus.android.runtimeMainActivity();
BluetoothAdapter = plus.android.importClass("android.bluetooth.BluetoothAdapter");
BAdapter = BluetoothAdapter.getDefaultAdapter();
BluetoothDevice = plus.android.importClass('android.bluetooth.BluetoothDevice');
BAdapter.startDiscovery()
var foundreceiver = plus.android.implements('io.dcloud.android.content.BroadcastReceiver', {
onReceive: function(context, intent) {
plus.android.importClass(intent);
console.log(intent.getAction());
var BleDevice = new BluetoothDevice();
BleDevice = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
console.log("蓝牙设备:" + BleDevice.getName() + BleDevice.getAddress());
}
});
var IntentFilterScan = plus.android.importClass('android.content.IntentFilter');
var filterScan = new IntentFilterScan();
filterScan.addAction(BluetoothDevice.ACTION_FOUND); //搜索设备
main.registerReceiver(foundreceiver, filterScan); //注册监听
1 个回复
喜洋洋liugp
你好 这个不一定是代码的问题 也有可能是mui调用原生安卓的速度慢