Manually pairing Bluetooth Decives in Android?

15.8k views Asked by At

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.

1

There are 1 answers

0
JimmyB On BEST ANSWER

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:

  1. Make your BT device discoverable
  2. Let Android search for and find the device and then initiate a connection
  3. Android will ask for the PIN for pairing with the device; enter the PIN.
  4. Once pairing was successful, Android stores the pairing information for future use, so that you can
  5. 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.