I am programming a sip application for Android. During the conversation, I have to record the microphone input and play the incoming sound. There should be additional use of the speakerphone. It should be compatible with Android 1.5+ (1.5, 1.6, 2.0, 2.1, 2.2, future versions) and portable devices.
OK So I use AudioTrack to play the incoming sound, AudioRecord to record data from the microphone and AudioManager.setSpeakerphoneOn () to turn the speakerphone on or off.
It sounds easy, but it's not as easy as it should be. AudioManager.setSpeakerphoneOn (false) does not work unless AudioManager.setMode (AudioManager.MODE_IN_CALL) is called. Therefore, I must be in MODE_IN_CALL.
Still fine and simple, and it works on my G1 with Android 1.6, an older Samsung phone, emulators, many of our client devices, etc. But it does not work everywhere :(
On a Samsung GT-P1000 tablet, I get a stream of 0, 0, 0, 0, ... as a microphone input. I think the same problem applies to Motorola phones (customers complain). After some test, I realized that it was caused by AudioManager.setMode (AudioManager.MODE_IN_CALL). This leads to the fact that the microphone does not work on some devices. But I have to call it, because otherwise I cannot turn off the speakerphone.
Is there an easy way to make this simple, correct, and working? And, if possible, without hell, for example, the very dangerous Sipdroid source code:
if (RtpStreamReceiver.samsung) { AudioManager am = (AudioManager) Receiver.mContext.getSystemService(Context.AUDIO_SERVICE); am.setMode(AudioManager.MODE_IN_CALL); am.setMode(AudioManager.MODE_NORMAL); }
or
void initMode() { samsung = Build.MODEL.contains("SAMSUNG") || Build.MODEL.contains("SPH-") || Build.MODEL.contains("SGH-") || Build.MODEL.contains("GT-"); if (Receiver.call_state == UserAgent.UA_STATE_INCOMING_CALL && (Receiver.pstn_state == null || Receiver.pstn_state.equals("IDLE"))) { setMode(AudioManager.MODE_NORMAL); }
Thank you very much yang