I would like to programmatically pair my mobile phone with medical sensor using Bluetooth interface. I have address and PIN necessary for connecting to device but I would like to avoid user interaction (pairing process - sensor configuration etc.)
I tried using unofficial Bluetooth API (http://code.google.com/p/android-bluetooth/) but it seems that this doesn't for Android 2.1 and above (I got LocalBluetoothDevice allways NULL, and people on their forum said that this is only for 1.X versions)
I saw that Android API has methods that do this pairing in background but they are labeled with #hide annotation. How do I access this?
Did anyone succeeded in this? (programmatically pairing) Any example?
Thanks!
I think you need to use createInsecureRfcommSocketToServiceRecord() which is introduced in API 10. I've got to get this working on Android 2.2, so I used reflection to call the method as per this method & it worked. I am identifying the Bluetooth device I connect to by its friendly name & setting it to not require PIN bonding, my Android APP now connects to it without the device having to be bonded or any PIN input, so its a security concern.
Related
Was going through Android documentation and had few doubts:
Using "Wi-Fi direct" in Android 4.0+, is it possible to establish
connection pragmatically with NON "Wi-Fi direct" enabled network device?
For example, is it possible to communicate with older smartphone (having Android 2.2 OS) with the latest 4.1 based Android Smartphone. I want to use Wi-Fi direct capablities to perform FTP operation on various kinds of smartphones (android, iOS)
Thanks.
I am using an APP named FileDrop which I think has the similar feature set you are looking for.
This is how it works:
4.1 based phone becomes GO and generates a Wi-Fi password to allow older phone to connect to it using legacy Wi-Fi just like connecting to a Wi-Fi access point. You can also use QR scanning instead of manual key-in of the password.
I hope you can get a sample code from them.
Sorry for no real help.
I am a newbie working on bluetooth, and I would like to get some advice regarding the pairing process. I have googled this but I did not find much information ...
My goal is simple: I want to do a pairing to a headset without entering a pin. I have an android (nexus S running Android 4.1.2) and an iphone (3GS running ios 6.1.3).
If I connect to a device like a Jabra BT3030 (bluetooth headset), the pairing is performed without asking me any pin code.
Now I want to do the same from an Ubuntu (with BlueZ 4.6), i.e. I fake a bluetooth headset by enable only the correct service and so on. I disabled the authentication.
When I pair my iphone to this device, no pin code is required (as expected), but when I connect from my Android device, it still asks me for a pin code, whereas I would expect to have the same behavior than with the Jabra.
Would you have any idea of what I am missing here?
Thanks in advance,
Best regards,
Guillaume
Android Uses UUID for pairing and connection for two devices...for two devices conneting, one device should send request and one should accept and for both UUID should be same...
Like also used bluetooth there I need to intall my android app to both the devices then only I can pair the two devices...because only that app is knowing the UUID. and for iPhone it may be different so if from the native code of iOS u can know the UUID ur android device can be paired through app...
The Standard password for a Jabra BT3030 is 0000. Many other bluetooth devices have a standard password. For the Case a system only accepts devices with passwords, and u cant enter a pasword on a device without keys :D
Maybe the solution is implementing the standard passwords for mutliple devices and use them instead f forcing a connection without password.
I would like to automatically connect via Bluetooth one Android device into another Android device as soon as that device is in it's Bluetooth coverage zone.
Cheers
This depends on the Bluetooth version supported on both devices.
BT2.1 or below requires a pin. You can hard code the pin (as many BT peripherals, such as headsets do).
For versions greater than BT 2.1, you can use 'just works' simple pairing, which doesn't require a pin but may prompt the user to allow it.
I don't know what the Android specific API to do these are though.
I was reading this
http://developer.android.com/guide/topics/wireless/bluetooth.html#QueryingPairedDevices
which is allot of help on how to pair,connect to a bluetooth device.
I have a situation where I have several BT devices that are in Non-Discover mode always. I know the MAC and the PIN of these devices. IS there a way in Android Dev to manually add devices to the PAIRED list so i can just use the connect as a client.
I understand this maual is written allot for V3. i think i will need to do this on 2.0 ; 2.1- has anybody done this before?
Basically these devices I want to connect to are power saving modules I used pre built BT modules to monitor daylight, another one humidity, etc.. every 3hrs or when interrupted and runs of a single battery for months. So turning off divcory on server saves immense power and prevents other people trying to connect and waste battery.
Not sure what you mean by "manually": Do you mean "manually" as in GUI/user interaction, or "manually" as "I do it in my own application code"?
Some suggestions though:
If you can make your BT devices discoverable at all, you could do it this way:
Make your BT device discoverable
Let Android search for and find the device and then initiate a connection
Android will ask for the PIN for pairing with the device; enter the PIN.
Once pairing was successful, Android stores the pairing information for future use, so that you can
Make your BT device invisible again.
From then on your app should be able to connect to the BT device at any time without further pairing operations.
If the said is not an option for you, maybe you want to go another way:
In current Android versions there are different API routines implemented which are neither documented nor exposed in the normal SDK. A hack kind of solution may be to use some of these "hidden" ("#hide"...) APIs, either via reflection or via modification of your SDK installation.
But be aware that this is always a hack and it may work on a specific device with a specific version of Android and is likely to break your app on another device and/or any other Android version.
Having said that, here comes some reference:
Example of how to access "hidden" bluetooth API.
Then, have a look at the source code for android.bluetooth.BluetoothDevice, e.g. here.
In there, public boolean createBond(){...} may do what you want.
My application needs to connect to a a2dp device over bluetooth and I want to "be able to query for the visible bluetooth devices, then, select a a2dp device and have it 'connect via a2dp' so that audio starts playing through the connected device" but my phone is running gingerbread (2.3.3).
I went through the basic bluetooth tutorial at http://developer.android.com/guide/topics/wireless/bluetooth.html and got to the part I need to connect to the bluetooth device and then I read the bottom of the page:
"Starting in Android 3.0, the Bluetooth API includes support for working with Bluetooth profiles." -> does this mean that I am S.O.L.? Is there any way to programmatically (why does stackoverflow mark programmatically as being misspelled?!) connect to a a2dp device using a pre-3.0 version of Android? Is my only option to direct the user to go into their settings/pull up the settings programmatically?? Because I'm able to do it through the settings, I guess I just assumed it would be possible via my application as well.
Help?
Some of the Bluetooth classes (profiles like BluetoothA2dp) are hidden in Gingerbread. It means that their declaration is annotated by #hide, and they are not included into the SDK (Android.jar). This is done intentionally, since these APIs are likely to be changed in newer Android versions. Generally it is not a good idea to use hidden APIs, since your App can stop working on newer Android versions, but if you are sure you want to, follow
http://devmaze.wordpress.com/2011/01/18/using-com-android-internal-part-1-introduction/
Once you get access to them do something like (just a hint):
BluetoothA2dp mBluetoothA2dp = new BluetoothA2dp(context);
BluetoothDevice device = BluetoothAdapter.getDefaultAdapter().
// Loop through paired devices
for (BluetoothDevice device : mBluetoothAdapter.getBondedDevices()) {
if (device.getName().contains("whatyouwant")) {
mBluetoothA2dp.addSink(device);
}
}
So, after much more research, it seems that it is impossible to programmatically connect to a A2DP device on a pre-3.0 Android device. I am going mark this as the answer but, if someone finds otherwise, please correct me on this as I would really like to do it programmatically.