I was challenged by a professor to develop a small application to demonstrate Bluetooth on Android. I knew nothing about Android development until 2 weeks ago when he gave me this task. I am also completely new to Java programming in general, so I'm starting far. But anyway...
So, I did most of the tutorial, and I read about Bluetooth in Android, looked at the bluetooth chat code sample, and now I'm trying to make my own small application. Therefore, for my demonstration, I will try to establish a connection between my real phone and my Bluetooth mouse. I want to move a piece on the screen of my phone in response to my mouse movement.
I have many problems, but still the main way is to open the socket with my unprotected mouse. When I try to use the listenUsingRfcommWithServiceRecord method, it asks for the UUID as a parameter. But my mouse most likely does not have a UUID response, so I assume this method is not good.
When I read the documentation about this method, it says that to open an insecure server socket using a device such as a mouse, I have to use the listenUsingInsecureRfcommWithServiceRecord method. But this method is not available when I call it, it is underlined in red, and Eclipse says that it is undefined for the type BluetoothAdapter.
private BluetoothServerSocket connectDevice(BluetoothAdapter adapter, BluetoothDevice device){ BluetoothServerSocket socket = null; try{ socket = adapter.listenUsingInsecureRfcommWithServiceRecord(device.getName(), UUID.randomUUID()); } catch(IOException e){ Toast.makeText(this, "Connection failed.\n" + e.getMessage(), Toast.LENGTH_SHORT); } return socket; }
Please do not cry if I do it all wrong, this is my first question here, and I start with Java programming.