Android JSR82 connect:未创建与蓝牙套接字的连接(失败或中止)

Android JSR82 connect:未创建与蓝牙套接字的连接(失败或中止),android,android-bluetooth,jsr82,Android,Android Bluetooth,Jsr82,所以有很多关于这个问题的帖子- 其他职位- 尝试了从反射到无反射的所有方法,但均无效- if(!mDeviceAddress.equals("") && BluetoothAdapter.checkBluetoothAddress(mDeviceAddress)) { Log.i(TAG, "Remote Device Name "+mDeviceName); bdDevice = mBluetoothAdapter.getRemoteDevi

所以有很多关于这个问题的帖子-

其他职位-

尝试了从反射到无反射的所有方法,但均无效-

if(!mDeviceAddress.equals("") && BluetoothAdapter.checkBluetoothAddress(mDeviceAddress))
{
    Log.i(TAG, "Remote Device Name  "+mDeviceName);

    bdDevice = mBluetoothAdapter.getRemoteDevice(mDeviceAddress);
    getConnected(bdDevice);
}


@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
public void getConnected(BluetoothDevice bdDevice)
{           
    if(bdDevice == null)
    {
        setSetting("STATUS", "Disconnected");
        Toast.makeText(getActivity(), 
        "Unable to get Remote Device!", Toast.LENGTH_SHORT).show();
        return;
    }
    else
    {
        Log.i(TAG, "Connecting Address--"+ bdDevice.getAddress());

        boolean isConnected = createInsecureRfcommSocket(bdDevice, 1);          

        if(!isConnected) 
        {
            for(int i=2;i<4;i++)
            {  
                if(!isConnected) 
                    isConnected = createInsecureRfcommSocket(bdDevice, i); 
                else
                    break;
            }
        }

    if(isConnected)
    {
        Log.i(TAG, "Connected Socket");
        setSetting("STATUS", "Connected");

        mConnectedThread = new ConnectedThread(socket);
        mConnectedThread.start();
        timeSyncCommand();
        mConnectedThread.writeByte(runCommand);

        startTime = System.currentTimeMillis();
    }
    else
    {
         try
         {
             socket = bdDevice.
             createInsecureRfcommSocketToServiceRecord(
             UUID.fromString("00001101-0000-1000-8000-00805F9B34FB"));
         }   
         catch(IOException io)
         {
            Toast.makeText(getActivity(), "Socket Create -" 
            + io.toString() , Toast.LENGTH_SHORT).show();
         }
         try
         {
            mBluetoothAdapter.cancelDiscovery();
            socket.connect();
         }
         catch(IOException io)
         {
            Log.i(TAG, "Socket Connect -"+io.toString());
         }

         if(socket.isConnected())
         {
            Log.i(TAG, "Connected Socket");
            setSetting("STATUS", "Connected");

            mConnectedThread = new ConnectedThread(socket);
            mConnectedThread.start();
            timeSyncCommand();
            mConnectedThread.writeByte(runCommand);

            startTime = System.currentTimeMillis();
         }
         else
         {
            Log.i(TAG, "Disconnected Socket");
            setSetting("STATUS", "Disconnected");
         }

       }    
     }
    }


    @TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
    public boolean createInsecureRfcommSocket(BluetoothDevice bdDevice, int i)
     {
         try 
        {
            Log.i(TAG,
            "Creating RFCOMM socket using reflection with Object "+i);
            //socket = bdDevice.createRfcommSocketToServiceRecord(my_UUID);
            Method m = bdDevice.getClass().
            getMethod("createInsecureRfcommSocket", new Class[] {int.class});
            socket = (BluetoothSocket) m.invoke(bdDevice, i);
            mBluetoothAdapter.cancelDiscovery();

            Log.i(TAG,"Attempt to connect to a remote device");
            socket.connect();
        }
        catch(IOException e)
        {
            setSetting("STATUS", "Disconnected");
            Log.i(TAG,"Exception raised "+e.getMessage());

            try 
            {
                socket.close();
                Log.i(TAG,
                "Cannot connect with address "+bdDevice.getAddress());
                e.printStackTrace();
            } 
            catch (IOException e1) 
            {
                Log.i(TAG,"Socket not closed");
                e1.printStackTrace();
            }   
        }
        catch (NoSuchMethodException e1) 
        {
            Log.i(TAG,"NoSuchMethodException");

            e1.printStackTrace();
        }
        catch (InvocationTargetException e2) 
        {
            Log.i(TAG,"InvocationTargetException");

            e2.printStackTrace();
        }
        catch (IllegalAccessException e3) 
        {
            Log.i(TAG,"IllegalAccessException");

            e3.printStackTrace();
        }
        catch (NullPointerException e4) 
        {
            Log.i(TAG,"NullPointerException");

            e4.printStackTrace();
        }
    }
Remote Device Name  RN-IAP-E281
Connecting Address--00:06:68:4D:E2:81
Creating RFCOMM socket using reflection with Object 1
Attempt to connect to a remote device
Exception raised [JSR82] connect: Connection is not created (failed or aborted).
Cannot connect with address 00:06:68:4D:E2:81
 Creating RFCOMM socket using reflection with Object 2
 Attempt to connect to a remote device
Exception raised [JSR82] connect: Connection is not created (failed or aborted).
Cannot connect with address 00:06:68:4D:E2:81
Creating RFCOMM socket using reflection with Object 3
Attempt to connect to a remote device
Exception raised [JSR82] connect: Connection is not created (failed or aborted).
Cannot connect with address 00:06:68:4D:E2:81
Disconnected Socket
------onReceive BroadcastReceiver------
Received Bluetooth Disconnected Request
------Returned from broadcast after disconnect------

任何帮助都将不胜感激

我也有类似的问题。对我来说,问题是我的SPP服务器绑定到一个已经使用过的通道,所以实际上android设备没有尝试连接到SPP服务器,而是其他一些东西。我修改了服务器的UUID,尝试连接到由该唯一UUID标识的通道,然后工作。因此,如果有人有问题,请检查您是否真的尝试连接到您想要连接的频道!你找到解决办法了吗?