2

Android Bluetooth Insecure Rfcomm private static final UUID MY_UUID = UUID.fromString("00001101-0000-1000-8000-00805F9B34FB");の「サービスの検出に失敗しました」からUUID を 下回りました。この UUID を使用して、Android 以外の他のハンドセット (Bada、Blackberry) を接続できます。以下は、Androidサンプルから取得したコードです/

**
     * This thread runs while attempting to make an outgoing connection
     * with a device. It runs straight through; the connection either
     * succeeds or fails.
     */
    private class ConnectThread extends Thread 
    {
        private final BluetoothSocket mmSocket;
        private final BluetoothDevice mmDevice;
        BluetoothSocket tmp = null;
        public ConnectThread(BluetoothDevice device) 
        {
            mmDevice = device;


            // Get a BluetoothSocket for a connection with the
            // given BluetoothDevice
            try 
            {
                tmp = device.createRfcommSocketToServiceRecord(MY_UUID);
                Log.d(TAG, "tmp = "+tmp.toString());
            }
            catch (IOException e) 
            {
                Log.e(TAG, "create() failed", e);
            }
            mmSocket = tmp;
        }

        public void run()
        {
            Log.i(TAG, "BEGIN mConnectThread");
            setName("ConnectThread");

            // Always cancel discovery because it will slow down a connection
            mAdapter.cancelDiscovery();

            // Make a connection to the BluetoothSocket
            try
            {
                // This is a blocking call and will only return on a
                // successful connection or an exception
                Log.d(TAG, " before connecting mmsocket.connect()");
                mmSocket.connect();
                Log.d(TAG, " after connecting mmsocket.connect()");
            }
            catch (IOException e) 
            {
                Log.d(TAG, " before connectionFailed()");
                connectionFailed();
                Log.d(TAG, " after connectionFailed()");
                Log.d(TAG, "after connectiofailed exception is: "+ e.toString());
                // Close the socket
                try 
                {
                    mmSocket.close();
                } 
                catch (IOException e2) 
                {
                    Log.d(TAG, "unable to close() socket during connection failure: "+ e2.toString());
                }

//                // Start the service over to restart listening mode
//                BluetoothChatService.this.start();
                return;
            }

            // Reset the ConnectThread because we're done
            synchronized (BluetoothService.this)
            {
                mConnectThread = null;
            }
            Log.d(TAG, " before connected mmsocket and mmdevice");

            // Start the connected thread
            connected(mmSocket, mmDevice);
            Log.d(TAG, "after connected mmsocket and mmdevice");
        }

        public void cancel() {
            try {
                mmSocket.close();
            } catch (IOException e) {
                Log.e(TAG, "close() of connect socket failed", e);
            }
        }
    }

サービスの検出に失敗しましたというエラーが表示されます。2 台の Android ハンドセットをペアリングしたいのですが、助けてください!!!

4

0 に答える 0