2011-06-16 131 views
0

我正在編寫一個代碼,用於偵聽藍牙設備斷開連接,然後執行某些操作。我會如何去做這件事?我不完全確定我想在它之後放置什麼,我想先把它整理出來。希望我對這個代碼沒有完全錯誤,因爲我是新開發人員。這是我到目前爲止有:收聽藍牙狀態

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

首先,使用BluetoothChat例如開始與與藍牙編碼是相當複雜的,這是不錯的工作代碼。你想看的是BluetoothChat.java中的handleMessage(),你需要保存狀態。當狀態從BluetoothChatService.STATE_CONNECTED更改爲BluetoothChatService.STATE_NONE時,設備已斷開連接。