我正在编写一个代码,用于侦听蓝牙设备断开连接,然后执行某些操作。我该怎么做呢?我还不确定我想把它放在它之后,我想我先把它整理好。希望我对这段代码并没有完全错,因为我是新手。这就是我到目前为止所做的:
private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
if (BluetoothAdapter.ACTION_ACL_DISCONNECTED.equals(action))
{ // This will be the followup action, once I figure out what I want it to be.
答案 0 :(得分:0)
首先,使用BluetoothChat示例开始,因为使用蓝牙进行编码非常复杂,并且拥有正常工作的代码很不错。你想看的是BluetoothChat.java中的handleMessage(),你需要保存状态。当状态从BluetoothChatService.STATE_CONNECTED更改为BluetoothChatService.STATE_NONE时,设备已断开连接。