Can anyone please provide us any source code for bluez implementation in android. Actually we are trying to make an application with GATT profile. This android application should connect with other device by Bluetooth connection. Please suggest me what should be the best way to send data to a non android device.
Asked
Active
Viewed 588 times
1 Answers
0
Look at Bluetooth chat example by Google, you also can use the same method to connect to a non android device. Specifically you will need this api
device.createRfcommSocketToServiceRecord(SerialPortServiceClass_UUID);
EDIT: You can also try using reflection to access another method like this
Method m = mmDevice.getClass().getMethod("createRfcommSocket", new Class[] {int.class});
mmSocket = (BluetoothSocket) m.invoke(mmDevice, Integer.valueOf(1));

Arveen
- 868
- 6
- 18
-
I have gone through the Bluetooth chat . But when I tried to connect with non android device but whenever the socket tries to connect(mmSocket.connect(); ) it is throwing IO-exception. But in case of two android devices it is working fine. Please suggest me.. – tanvir Sep 03 '12 at 10:00
-
then catch the exception and start debugging, i can confirm that it works for non android devices, as i have used the same api to connect to a separate bluetooth module – Arveen Sep 03 '12 at 10:04
-
I am getting Service discovery failed IO exception. do u faces this kind of exception. – tanvir Sep 03 '12 at 10:11
-
You are probably using the wrong UUID Both the host and slave should be on the same UUID, 00001101-0000-1000-8000-00805F9B34FB is a common UUID for a serial connection. – Arveen Sep 03 '12 at 11:16
-
connection is done but what is the way to send data to non android device .. I am doing output stream but its not working.. Please tell me what is the way to send any data to non android device. – tanvir Sep 03 '12 at 11:36
-
Output stream is the correct way, something like this.. OutStream.write(a_bytesOfData) – Arveen Sep 03 '12 at 11:41
-
yeah that what i m doing but nothing is happening on the non android device .How will I understand it is working as I cant debug on non android device. – tanvir Sep 03 '12 at 11:43
-
What device exactly are you trying to connect to ? – Arveen Sep 03 '12 at 12:35
-
its lg simbean OS. I mean if u can post me the code for sending data to another non android device it will be very helpful. – tanvir Sep 03 '12 at 12:44
-
http://stackoverflow.com/questions/9188639/send-file-to-other-bluetooth-device-from-android?lq=1 – Arveen Sep 03 '12 at 13:17
-
if you need to send something else you need a app running on the other os – Arveen Sep 03 '12 at 13:18
-
I tried to send a jpg file. But nothing received in the non andorid phone... :( – tanvir Sep 03 '12 at 13:42