我使用的uni-app
发送
已搜索的蓝牙:
蓝牙名称:{ {item.name}}
SN:{ {item.SN}}
已匹配的蓝牙:
蓝牙名称:{ {item.name}}
SN:{ {item.SN}}
打开蓝牙
关闭蓝牙
搜索蓝牙
varmain, Context, BluetoothManager, BluetoothAdapter, BManager, BAdapter,BluetoothDevice,IntentFilter,bluetoothSocket,device;
exportdefault{
data() {return{
bArray:[],//用于搜索蓝牙去重用的
no_match_list:[],//没有配对的蓝牙列表
match_list:[],//已配对的蓝牙列表
send_data_onoff:false,
send_data_list:'',//要发送的数据
};
},
onShow() {//获取android应用Activity对象
main =plus.android.runtimeMainActivity();
Context= plus.android.importClass("android.content.Context");
BManager=main.getSystemService(Context.BLUETOOTH_SERVICE);//蓝牙适配器
BluetoothAdapter = plus.android.importClass("android.bluetooth.BluetoothAdapter");//蓝牙本地适配器
BAdapter =BluetoothAdapter.getDefaultAdapter();//蓝牙设备
BluetoothDevice = plus.android.importClass('android.bluetooth.BluetoothDevice');//过滤器
IntentFilter = plus.android.importClass('android.content.IntentFilter');
},
methods:{/**
* 根据蓝牙地址,连接设备
* @param {O