android藍牙自動配對的有關問題


android藍牙自動配對遇到是SSP配對時,那種只彈出“藍牙配對申請”框,只需要點擊“配對”和“不配對”,這時候我的廣播監聽函數如下

  public class MessageReceiver extends BroadcastReceiver {
public void onReceive(Context context, Intent intent) {
    if (action.equals(BluetoothDevice.ACTION_PAIRING_REQUEST)) {
         BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
         try {
             BtConnectOperation.BtSetPairingConfirmation(device.getClass(), device);
         } catch (Exception e) {
             // TODO Auto-generated catch block
     e.printStackTrace();
         }
         mConnService.pairEnd();
    }
}
}


其中這個BtSetPairingConfirmation函數如下,使用反射機制

  //設置確定
    static public boolean BtSetPairingConfirmation(Class btClass, BluetoothDevice device)
     throws Exception {
        Method SetPairingConfirmationMethod = btClass.getMethod("setPairingConfirmation", 
         boolean.class);
        Boolean returnValue = false;
        returnValue = (Boolean)SetPairingConfirmationMethod.invoke(device, true);
        
        return returnValue;
    }


爲何還是不能直接自動配對呢,還是會彈出“藍牙配對申請”框,請大神們給些意見,謝謝啊 
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章