Я хочу использовать BluetoothHeadsetClient. для использования этого скрытого кода SDK я использую отражение.BluetoothHeadsetClient: не удалось связать с Bluetooth-гарнитурой Клиентское обслуживание с намерением
Я хочу назвать
mBluetoothAdapter.getProfileProxy(this, mHeadsetProfileListener, BluetoothProfile.HEADSET_CLIENT);
но BluetoothProfile.HEADSET_CLIENT скрыт в BluetoothProfile.java. для того, чтобы решить эту проблему, я выполнить следующий код
значениеprotected BluetoothProfile.ServiceListener mHeadsetProfileListener = new BluetoothProfile.ServiceListener()
{
@Override
public void onServiceDisconnected(int profile) {
}
@Override
public void onServiceConnected(int profile, BluetoothProfile proxy)
{
mlisten = mHeadsetProfileListener;
mHeadSetCleintObj = proxy;
// reflection for getting the HEADSET_CLIENT type
try {
Class classRef = Class.forName("android.bluetooth.BluetoothProfile");
Field field = classRef.getField("HEADSET_CLIENT");
if(profile == BluetoothProfile.HEADSET) {
mBluetoothAdapter.getProfileProxy(getApplicationContext(), mHeadsetProfileListener, field.getInt(proxy));
}
}
catch (Exception e) {
e.printStackTrace();
}
mBluetoothHeadset.getConnectedDevices();
}
};
@Override
public void onDestroy() {
unregisterReceiver(mPairReceiver);
super.onDestroy();
}
field.getInt (прокси) == 16 -> BluetoothProfile.HEADSET_CLIENT как я хотел. но когда я бегу
mBluetoothAdapter.getProfileProxy(getApplicationContext(), mHeadsetProfileListener, field.getInt(proxy));
я вижу следующее сообщение об ошибке
E/BluetoothHeadsetClient﹕ Could not bind to Bluetooth Headset Client Service with Intent { act=android.bluetooth.IBluetoothHeadsetClient }
вы знаете, как решить этот тип ошибки?
Спасибо!