const main = plus.android.runtimeMainActivity(); const IntentFilter = plus.android.importClass('android.content.IntentFilter'); const BluetoothAdapter = plus.android.importClass("android.bluetooth.BluetoothAdapter"); const BluetoothDevice = plus.android.importClass("android.bluetooth.BluetoothDevice"); export function searchBDevices () { const BAdapter = BluetoothAdapter.getDefaultAdapter(); const filter = new IntentFilter(); const bdevice = new BluetoothDevice(); BAdapter.startDiscovery(); const receiver = plus.android.implements('io.dcloud.android.content.BroadcastReceiver', { onReceive: function (context, intent) { plus.android.importClass(intent); const isFinished = intent.getAction() == "android.bluetooth.adapter.action.DISCOVERY_FINISHED"; if(isFinished) { console.log('扫描结束', context); } } }) filter.addAction(bdevice.ACTION_FOUND); filter.addAction(BAdapter.ACTION_DISCOVERY_STARTED); filter.addAction(BAdapter.ACTION_DISCOVERY_FINISHED); filter.addAction(BAdapter.ACTION_STATE_CHANGED); main.registerReceiver(receiver, filter); //注册监听 }