I'm pretty new to android app development and java, but I've been working on this project and have run into some problems. I connected a USB Bluetooth Dongle to my Raspberry Pi and the goal is to have my android app sense whenever I am in range of the Raspberry Pi. I know the MAC address of the dongle. All I really need to do is connect to it, but whenever I run the btSocket.connect(), I'm getting the catch. So here's my code so far.
BluetoothAdapter btAdapter = BluetoothAdapter.getDefaultAdapter();
BluetoothDevice transmitter = btAdapter.getRemoteDevice("00:15:83:0C:BF:EB");
try { btSocket = transmitter.createInsecureRfcommSocketToServiceRecord(MY_UUID);
} catch (IOException e) {
// TODO Auto-generated catch block
Log.d(getClass().getName(), "Creating socket failed");
}
try {
btSocket.connect();
} catch (IOException e) {
// TODO Auto-generated catch block
Log.d(getClass().getName(), "Connection failed");
}
Here's the stack Trace since I cannot post images yet.
java.io.IOException: Unable to start Service Discovery
at android.bluetooth.BluetoothSocket$SdpHelper.doSdp(BluetoohtSocket.java:455)
at android.bluetooth.BluetoothSocket.connect(BluetoothSocket.java:230)
at com.example.alarmservice.ScheduledService.onHandleIntent(ScheduledService.java:49)
at android.app.IntentService$ServiceHandler.handleMessage(IntentService.java:65)
at android.os.HAndler.dispatchMessage(Handler.java:89)
at android.os.Looper.loop(Looper.java:137)
at android.os.HandlerThread.run(HandlerThread.java:60)
I'm also confused on how to know what to use for MY_UUID
. Thanks for your help!