6

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です。

4

2 に答える 2

4

現在、一部の電話でBluetooth(SPPを使用)に問題があります。試すことができることの1つは、ソケットを作成するときにリフレクションを使用することです。

Bluetoothサービスの開発中にNexusSを使用しました(実際にはlistenUsingRfcommWithServiceRecordメソッドを使用しています)。この電話では正常に機能します。SonyEricssonXperiaARCおよびSonyEricssonX10MiniProでも正常に動作します。HTC Wildfire(2.2.1)、HTC Legend(2.2)、Samsung Galaxy S(2.2.1)では動作しませんでした。

また、データを受信して​​いるデバイスも、あなたと同じようにBluetooth 1.2を使用しているので、問題はないはずです。

リフレクションを使ってみたところ、突然Wildfireに成功しましたが、残念ながらLegendやGalaxySではまだ進歩がありません。これが行き詰まっています。多くのフォーラムは、一部のメーカーが独自のBluetoothスタックを持っていると主張しているので、これがこれらの問題の原因だと思います。とにかく、頑張ってください!

UUID MY_UUID = UUID.fromString("00001101-0000-1000-8000-00805f9b34fb");

Method m = mAdapter.getClass().getMethod("createRfcommSocketToServiceRecord", new Class[] { UUID.class });
tmpSocket = (BluetoothServerSocket) m.invoke(mAdapter, new Object[] { MY_UUID });
于 2011-06-30T08:23:40.110 に答える
1

繰り返しますが、これはその電話のBluetoothのバグのようですが、同じBTチップとバージョンを持つ他の電話にはその問題はありません

于 2011-06-28T14:12:56.953 に答える