Reputation: 61
As I mentioned above, I get the AudioManager instance and initiate it with MODE_IN_CALL, however when I close my app(not killed), I can't make my earphone to work when using other apps, please help.Is it that I set the wrong mode the reason of my problem? Here's the code:
private boolean initDefaultSensor() {
if (proximitySensor != null) return true;
if (sensorManager == null || audioManager == null) return false;
proximitySensor = sensorManager.getDefaultSensor(Sensor.TYPE_PROXIMITY);
if (proximitySensor == null || audioManager == null) {
return false;
}
audioManager.setMode(AudioManager.MODE_IN_CALL);
return true;
}
also i called some other methods that may be relative to this question
public void OpenSpeaker() {
try {
if (!audioManager.isSpeakerphoneOn()) {
audioManager.setSpeakerphoneOn(true);
}
} catch (Exception e) {
e.printStackTrace();
}
}
public void CloseSpeaker() {
try {
if (audioManager != null) {
if (audioManager.isSpeakerphoneOn()) {
audioManager.setSpeakerphoneOn(false);
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
Upvotes: 2
Views: 978
Reputation: 467
As per my research, the audioManager.setMode(AudioManager.MODE_IN_CALL)
, doesn't work above Android 4.4, and is accessible only by system apps/services. If you try to getMode()
, you will get AudioManager.MODE_NORMAL
in return.
However, if you want to use it in Android L, you can use audioManager.setMode(AudioManager.MODE_IN_COMMUNICATION)
.
Upvotes: 1