Pairing your Android-phone with your computer over bluetooth: easy.
Streaming your audio to your computer: easy.
Connect automatically when in range: not an option.
I would have expected this to happen automatically or to be an option. Too bad but at the moment of writing this is not an option (yet?) in Android 2.2 (Froyo).
As this took me some time to find out I decided to put it online and maybe someone somewhere can find good use for it.
Connecting is actually as simple as calling a command from within a script written for Scripting Layer for Android (SL4A) and the Python-interpreter (which can be installed from inside SL4A):
uuid = '00001108-0000-1000-8000-00805F9B34FB'
pcBTAddress = 'YOUR-PC-BT-ADDRESS'
droid = android.Android()
(click here for script in QR-format to import into SL4A)
The uuid used to connect to the pc is actually the uuid for a headset-connection. This will be transformed into an A2DP connection by Android when you start or are playing music.
When the ‘correct’ uuid for A2DP is used (either 0000110B-0000-1000-8000-00805F9B34FB (Audio Sink Service) or 0000110D-0000-1000-8000-00805F9B34FB (Advanced Audio Distribution Service) (see Android-source)) we get the error:
java.io.IOException: Service discovery failed
Using the headset uuid pulls of the magic to make it work.
Script was tested with the following setup:
Android: CyanogenMod 6.0 (Froyo, Android 2.2)
Scripting Layer for Android R1 + Python for Android R1
Windows 7 with Qualcomm drivers
I use this script at home in combination with Tasker to turn on bluetooth and automatically connect to my pc when I plugin my charger.