A headset device has be connected to my phone.Now a phone call is coming, I want to answer the call just use the telephone not by the headset. How to do this ?
Any help will be appreciate!
A headset device has be connected to my phone.Now a phone call is coming, I want to answer the call just use the telephone not by the headset. How to do this ?
Any help will be appreciate!
No more words,look at these codes.You should listen the PhoneStateListener's CALL_STATE_OFFHOOK and call the setHandsetPhone() at a delay time.
private void setHandsetPhone()
{
if (isBluetoothAvailable() && isBluetoothAudioConnected())
{
disconnectBluetoothAudio();
}
//am == AudioManager
if (am.isSpeakerphoneOn())
{
am.setSpeakerphoneOn(false);
}
}
private boolean isBluetoothAvailable()
{
printLog("isBluetoothAvailable()...");
// Check if there's a connected headset, using the BluetoothHeadset API.
boolean isConnected = false;
if (mBluetoothHeadset != null)
{
List<BluetoothDevice> deviceList = mBluetoothHeadset.getConnectedDevices();
if (deviceList.size() > 0)
{
isConnected = true;
}
}
return isConnected;
}
/**
* @return true if a BT Headset is available, and its audio is currently
* connected.
*/
private boolean isBluetoothAudioConnected()
{
if (mBluetoothHeadset == null)
{
return false;
}
List<BluetoothDevice> deviceList = mBluetoothHeadset.getConnectedDevices();
if (deviceList.isEmpty())
{
return false;
}
BluetoothDevice device = deviceList.get(0);
boolean isAudioOn = mBluetoothHeadset.isAudioConnected(device);
return isAudioOn;
}
private void disconnectBluetoothAudio()
{
if (mBluetoothHeadset != null)
{
Class clazz = mBluetoothHeadset.getClass();
try
{
Method method = clazz.getMethod("disconnectAudio",
new Class[] {});
System.out.println("result-" + method.invoke(mBluetoothHeadset));
}
catch (Exception e)
{
e.printStackTrace();
}
}
}