How to create an Android RFCOMM socket without any input from the user?
At the end, I can say that you can't.
Even if you find a way, using wrappers, writing C modules and so on, android evolution will probably change the thing you're using.
And so, there's no option. Sadly.
Let's see how Android Bluetooth API will change in the future.
Comments
-
Enrico Carlesso almost 2 years
Here's the scenario:
I need to write an application for Android to create a RFCOMM socket to a PC with a Bluetooth dongle (I'm going to write the server too).
My requirement is that the user doesn't have to pair device manually.
Actually, with a big hack, I'm using the createInsecureRfcommSocket.
A little scenario: I've an Android application which exchanges information with a Linux box with a RFCOMM socket opened. I can manually set the PIN on the devices (hard coding it IS an option)
I'm looking for different roads:
Write a JNI wrapper
As has been done here by Max Kellermann, I can write a JNI layer to make all the pairing phase. This should be a good option, but there's a problem:
The NDK 4b does not provide libbluetooth libraries, so -lbluetooth fails, as well as the NDK v.3.
Options:
- Find the NDK 1.5 (which includes lib bluetooth). After days of web search I've been not able to find out. Anyone has or knows where I can find it?
- Compile libbluetooth for Android by myself and use them for -lbluetooth. No lucky there, I'm not able to build them. Any hint?
Use something exposed by the APIs
Any one know how can I use createRfcommSocketToServiceRecord and have the user not to manually pair the device? Is it possible? How should I write the server?
Something I do not know
Maybe (sure!) there is something I do not know. Maybe I can use something else? Not RFCOMM? SDP?
Maybe I can manually pair with the Android API?
I hope to have been clear enough, if not just ask. And again, as it's not the first time, I'm in your hands :)
Thanks for all the support guys!
-
Chris Stratton over 13 yearsSpeculating, but I would not be surprised if it's intentionally designed so that user involvement (approval) is required for pairing. At least that would be consistent with other places where the android design requires user interaction for security reasons.
-
Enrico Carlesso over 13 yearsYes, but the "official" api are not the only way. For that I'm asking about ndk 1.5, build the libbluetooth or the other @hide functions.
-
Chris Stratton over 13 yearsIf libbluetooth has been removed, most likely the older version wouldn't work on a newer android version even if you found it. That's the constant warning against using non-public API's - future changes may break them.
-
Squonk over 13 yearsI'm not sure I understand why you want this to work without the need for pairing manually (which is a fairly trivial thing for the user to do and is a one-time procedure).
-
Enrico Carlesso over 13 yearsI understand your point, and I agree. But it's a requirement for a project I'm involved. And the explanation is quite trivial, let's think about some kind of work which need to check a lot of different "things" which expose some bluetooth services. Pairing every time with the device is simply a waste of time.
-
techi.services over 13 yearsIs this what you need code.google.com/p/androidobex/downloads/… ?
-
mchang over 13 yearsEnrico, I'm sure this doesn't answer your question, but maybe it's worth asking -- are there any other communication mechanisms you can use to get this job done? BT is annoying, a bit. One thing you might do is encode your data into the BT device name that your phone broadcasts, and then a scan for devices will get that name (which is a few bytes of data).
-
Gareth Davidson over 13 yearsWhat's your use-case here? If you're querying things to find out if a service is available on a device, wouldn't SDP be a better option? I'm pretty sure you don't have to pair for service discovery.
-
Enrico Carlesso over 13 yearsThanks all for the hints. With order: @sugarynugs thanks, I have been able to compile the by myself but it's not enough. Android itself has a very strange way to use bluez... @mchang We are currently using both BT and wifi connection, but in some scenario BT is mandatory. @Gaz yes, but whit sdp I can only find services, but I need to have a channel over which communicate... Once I've fount the rfcomm socket broadcasted by sdp I must connect to it, thus pairing is needed...
-
Enrico Carlesso over 13 yearsHave you read the question? Because I cannot understand the answer... It does not fit at all.
-
Lee Taylor over 11 yearsThis has been copied and pasted from androidjavadoc.com/1.0_r1_src/android/bluetooth/…. Please add your own input.
-
Enrico Carlesso about 3 yearsThanks for the reply :D I need to point out the question was from November 2010 though :D