我的應用我試圖以編程方式配對藍牙設備。我能夠顯示我想要配對的設備的配對對話框,並且可以輸入PIN碼。當我按「對」時,對話框被刪除,沒有任何反應。如何以編程方式配對藍牙設備在Android
我只需要支持與Android 2.0及更高版本的設備。
目前我使用下面的代碼來開始配對的進展:
public void pairDevice(BluetoothDevice device) {
String ACTION_PAIRING_REQUEST = "android.bluetooth.device.action.PAIRING_REQUEST";
Intent intent = new Intent(ACTION_PAIRING_REQUEST);
String EXTRA_DEVICE = "android.bluetooth.device.extra.DEVICE";
intent.putExtra(EXTRA_DEVICE, device);
String EXTRA_PAIRING_VARIANT = "android.bluetooth.device.extra.PAIRING_VARIANT";
int PAIRING_VARIANT_PIN = 0;
intent.putExtra(EXTRA_PAIRING_VARIANT, PAIRING_VARIANT_PIN);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent);
}
開始配對請求我停止掃描新設備之前。
我的應用有以下藍牙權限:
- android.permission.BLUETOOTH_ADMIN
- android.permission.BLUETOOTH
我花了幾天l對這個確切問題的解決方案進行補充。看起來谷歌認爲強制配對是一個安全問題,所以你在這裏列出的ACTION類型實際上並不存在。我發現你在這裏引用的類:http://developer.oesf.biz/em/developer/reference/cinnamon/android/bluetooth/BluetoothDevice.html#ACTION_PAIRING_REQUEST 但它不在官方文檔中: http:// developer .android.com/reference/android/bluetooth/BluetoothDevice.html – moonlightcheese 2011-06-24 18:40:07
@FireFLy你有什麼解決方案嗎? – Pawan 2012-04-15 12:31:29
你有解決方案嗎? – 2012-06-14 21:29:07