Android中的蓝牙错误服务发现失败

我从Android服务发现失败中得到UUID低于蓝牙不安全Rfcomm私有静态最终UUID MY_UUID = UUID.fromString(“00001101-0000-1000-8000-00805F9B34FB”); 使用此UUID,我可以连接除android以外的其他手机(Bada,Blackberry)。 下面是我从android sample /

**
     * 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手机请帮忙!!!

链接地址: http://www.djcxy.com/p/82011.html

上一篇: bluetooth error service discovery failed in android

下一篇: Frame size of UIView when loaded from Nib?