简体   繁体   中英

Connection between android and PC bluetooth applications

I am working on a bluetooth application which involves connection of my android bluetooth application with a server running on computer. The server is also a bluetooth application made using blue-cove api.

The problem i am facing now that i am unable to make connection between my mobile app and that computer server application.

here is my code for android app:

 try {
            // Connect the device through the socket. This will block
            // until it succeeds or throws an exception
            mySocket = myDevice.createRfcommSocketToServiceRecord(MY_UUID);
            mySocket.connect();
            toast = Toast.makeText(context, "Connection established",   thisClass.duration);
            toast.show();
          } catch (IOException connectException) {
            // Unable to connect; close the socket and get out
            try {
                mySocket.close();
                toast = Toast.makeText(context, "Connection not established", thisClass.duration);
                toast.show();
            } catch (IOException closeException) { }
            return;
        }

Where is the problem or what possibly i am missing in it. And also i am having ambiguity in the understanding of socket.connect() method. Kindly help me in this regard.

I just finished working on a similar application and had problems connecting. It would help to see a bit more of your code but the excerpt above looks like the example I was following. I would start by checking that the MY_UUID exists on the PC that you are trying to connect to.

I have posted my example, both the client and server, on my blog at http://digitalhacksblog.blogspot.com/2012/05/android-example-bluetooth-simple-spp.html .

Hope this helps.

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