I have the same problem. I have an open source project here: http://code.google.com/p/a2dpvolume/
I need a way to know what remote device(s) are currently active. I would have thought getRemoteDevice([mac address]) would have only returned active remote devices but it actually returns any bonded device. I have searched the Android documentation and examples and still cannot find a way to know what is connected. I can only get the bonded devices.
I now figured out how to use the intent that is sent on the acl_connected intent to find the connected device:
First register to be notified when a bluetooth device connects:
// create intent filter for a bluetooth stream connection
IntentFilter filter = new IntentFilter(android.bluetooth.BluetoothDevice.ACTION_ACL_CONNECTED);
this.registerReceiver(mReceiver, filter);
Then see what connected
private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
BluetoothDevice bt = (BluetoothDevice) intent.getExtras().get(BluetoothDevice.EXTRA_DEVICE);
btConn = bt;
if(bt.getBluetoothClass().getDeviceClass() == BluetoothClass.Device.AUDIO_VIDEO_HIFI_AUDIO)
{
//Toast.makeText(context, bt.getName() + bt.getAddress(), Toast.LENGTH_LONG).show();
getOldvol();
setVolume(am2.getStreamMaxVolume(AudioManager.STREAM_MUSIC), a2dp.Vol.service.this);
}
}
};
Notice the onReceive function receives the context and intent. That intent contains the bluetooth device that just connected. The code above retrieves that device from the intent. The example toast (commented out here) shows how to see the address and name of that connected device. Your program will just need to keep track of that connected and disconnected. I am still looking for a way to query active connections. I think this can be done by looking at all the RFCOMM entries that are active, but not sure.