Problems connecting with bluetooth Android

前端 未结 2 944
轮回少年
轮回少年 2020-12-29 13:00

I\'m trying to open a socket bluetooth between a milestone and a pc but the device can not connect. I hope I am sending the code help.

public class Bluetooth         


        
2条回答
  •  太阳男子
    2020-12-29 13:38

    The createRFcommSocketToServiceRecord method is not working in Android 2.1/2.2. There is a workaround to call a non-public method to create the socket:

    BluetoothDevice hxm = BluetoothAdapter.getDefaultAdapter().getRemoteDevice(device.getAddress());
    Method m;
    m = hxm.getClass().getMethod("createRfcommSocket", new Class[]{int.class});
    socket = (BluetoothSocket)m.invoke(hxm, Integer.valueOf(1)); 
    

    This is taken from the following question: Disconnect a bluetooth socket in Android

    Regards, Michael

提交回复
热议问题