简体   繁体   中英

Connect PC and Android phone with bluetooth(c#)

I am trying to connect my computer with android phone to transmit some data. For computer programming language i have chosen c#.

On computer the code looks like this:

var wantedAddress="303926627f06"; 
var addr = BluetoothAddress.Parse(wantedAddress);
var cli = new BluetoothClient();
cli.Connect(addr, new Guid("{00001101-0000-1000-8000-00805f9b34fb}"));

And on a android phone code looks like:

private UUID uuid = UUID.fromString("00001101-0000-1000-8000-00805f9b34fb");
private BluetoothAdapter btAdapter= BluetoothAdapter.getDefaultAdapter();
private BluetoothServerSocket server=btAdapter.listenUsingRfcommWithServiceRecord("App name",uuid);
while(isRunning)
{
    try {
        BluetoothSocket socket=server.accept();

    } catch (IOException e) {
        isRunning=false;

        e.printStackTrace();
    }
}

After trying to connect to the phone i get this error:

SocketException:
The requested address is not valid in its context 303926627F06:0000110100001000800000805f9b34fb

Does anyone know what is wrong?

Thank you for help! Jure

See error codes at https://32feet.codeplex.com/wikipage?title=Errors So that suggests that the client is not finding the server with the expected UUID running on the target device. Now why...

If you use 32feet.NET SdpBrowser sample and list all the SDP Services "(over L2CAP)" what do you see?

Are you connecting to the correct device address?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM