I am developing an application where I have to connect to Bluetooth device on Android 4.3.
I can scan and connect to the device, and I want to connect to multiple BLE device and list them.
I have find the getConnectedDevices(), but it has multiple type in BluetoothHeadset , BluetoothProfile and BluetoothA2dp.
**First question is **What the different between there three API ??? Which is better ??****
I have try the code of the following:
public class Main extends Activity {
private BluetoothHeadset mBluetoothHeadset;
private BluetoothAdapter mBluetoothAdapter;
private BluetoothProfile.ServiceListener mProListener = new BluetoothProfile.ServiceListener() {
@Override
public void onServiceDisconnected(int profile) {
// TODO Auto-generated method stub
if(profile == BluetoothProfile.HEADSET) {
mBluetoothHeadset = null;
}
}
@Override
public void onServiceConnected(int profile, BluetoothProfile proxy) {
// TODO Auto-generated method stub
if(profile == BluetoothProfile.HEADSET) {
mBluetoothHeadset = (BluetoothHeadset) proxy;
}
}
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
mBluetoothAdapter.getProfileProxy(this, mProListener, BluetoothProfile.HEADSET);
}
I have reference the following, but I don't know how to continue. How to get bluetooth connected devices using BluetoothHeadset API
Second question:
Where should I type the List<BluetoothDevice> devices = mBluetoothHeadset.getConnectedDevices();
in??
Third question
Can I click the device which list by getConnectedDevices() and operation after I click such as setOnItemClickListener
??
I'm new to this. Thanks for everyone's direction.