HTCmyTouch3GをSPP経由で電話にデータをストリーミングするBluetoothデバイスとペアリングしようとしています。チャットの例を調べたところ、必要なデータレートが高く、チャットの例ではUIスレッドがブロックされているため、必要なものが不足していることがわかりました。しかし、私の主な問題は、現在ペアリングされていないデバイスを接続しようとすると、デバイスがペアリングコードを必要とする場合、BluetoothAPIはダイアログを自動的にポップアップすることを示しています。これは決して起こりません。どうすればそれが確実に行われるのですか?これが私のコードです...
BluetoothSocket btSocket;
String macAddress = data.getStringExtra("mac");
Log.d(TAG, "Found Device " + macAddress);
// Get the Bluetooth adapter on the device
BluetoothAdapter bta = ((MyApplication)this.getApplication()).getBtState();
BluetoothDevice btDevice = bta.getRemoteDevice(macAddress);
BluetoothSocket tmp = null;
try {
tmp = btDevice.createRfcommSocketToServiceRecord(UUID.fromString("00001101-0000-1000-8000-00805F9B34FB"));
} catch (IOException e) {
e.printStackTrace();
}
if (tmp != null) {
btSocket = tmp;
bta.cancelDiscovery();
try {
btSocket.connect();
} catch (IOException e) {
try {
Log.e(TAG, "------------- Close IOException");
btSocket.close();
} catch (IOException e2) {
Log.e(TAG, "unable to close() socket during connection failure", e2);
}
}
}
これが私も受けるエラーです:
ERROR/BluetoothEventLoop.cpp(149): event_filter: Received signal org.bluez.Adapter:DeviceCreated from /org/bluez/14284/hci0
ERROR/BluetoothEventLoop.cpp(149): event_filter: Received signal org.bluez.Adapter:PropertyChanged from /org/bluez/14284/hci0
ERROR/BluetoothEventLoop.cpp(149): event_filter: Received signal org.bluez.Device:PropertyChanged from /org/bluez/14284/hci0/dev_00_02_5B_00_A5_0B
ERROR/BluetoothEventLoop.cpp(149): event_filter: Received signal org.bluez.Device:PropertyChanged from /org/bluez/14284/hci0/dev_00_02_5B_00_A5_0B
DEBUG/BluetoothService(149): updateDeviceServiceChannelCache(00:02:5B:00:A5:0B)
DEBUG/BluetoothService(149): uuid(application): 00001101-0000-1000-8000-00805f9b34fb 1
DEBUG/BluetoothService(149): Making callback for 00001101-0000-1000-8000-00805f9b34fb with result 1
VERBOSE/BluetoothEventRedirector(13691): Received android.bleutooth.device.action.UUID
ERROR/MainApp(14272): ------------- Close IOException
ERROR/BluetoothService.cpp(149): stopDiscoveryNative: D-Bus error in StopDiscovery: org.bluez.Error.Failed (Invalid discovery session)
ERROR/BluetoothEventLoop.cpp(149): event_filter: Received signal org.bluez.Device:PropertyChanged from /org/bluez/14284/hci0/dev_00_02_5B_00_A5_0B
VERBOSE/BluetoothEventRedirector(13691): Received android.bleutooth.device.action.UUID
バグのように見えるこれについての奇妙なことの1つは、このコードを実行して失敗した場合、Bluetoothをオフにしてからオンに戻すと、スタックにペアリングされて表示されることです。私が理解していることから、myTouchのBluetoothチップは2.1であり、接続しようとしているチップは1.2です。