What I'm trying to do is to make call from my app and turn on speaker in this call.
Everything was okay on android 4.0, I've just set audiomanager.setSpeakerphoneOn(true) before starting call intent.
But on android 4.1 PhoneUtils checkin speaker state before call and turn it off(logcat):
D/PhoneUtils( 1029): about to activate speaker
D/PhoneUtils( 1029): activateSpeakerIfDocked()...
I/PhoneUtils( 1029): Forcing speaker off when initiating a new outgoing call...
I've also tried to listen call state using : mTelephonyManager.listen(receiver, PhoneStateListener.LISTEN_CALL_STATE);
After this receiver will catch 3 states:
IDLE(don't interesting for mee)
CALL_STATE_RINGING(also don't interesting because I need work with outgoing calls)
CALL_STATE_OFFHOOK(i though this one will help)
But last "event" was also send before PhoneUtils check speaker state(logcat):
11:43:48.089 D/KeyguardViewMediator( 665): keyguard receiver action : android.intent.action.PHONE_STATE
11:43:48.089 D/KeyguardViewMediator( 665): keyguard receiver TelephonyManager.EXTRA_STATE : OFFHOOK
11:43:48.099 D/PhoneUtils( 977): setAudioMode()...OFFHOOK
11:43:48.099 D/MyPhoneStateListener:main( 2590): catching call state CALL_STATE_OFFHOOK
11:43:48.099 D/MyPhoneStateListener:main( 2590): turning phone speaker on
...
11:43:48.119 D/PhoneUtils( 977): about to activate speaker
11:43:48.119 I/PhoneUtils( 977): Forcing speaker off when initiating a new outgoing call...
If somebody faced with same problem or have a solutuion?
Thanks!
I've had this problem this week..
Reading the jelly bean code source, i've found this code
// This is not an error but might cause users' confusion. Add log just in case.
Log.i(LOG_TAG, "Forcing speaker off when initiating a new outgoing call...");
PhoneUtils.turnOnSpeaker(app, false, true);
So that's it, in version 4.1 android forces speaker off in incoming and outgoing calls.
My solution is turn on the speaker in my call state broadcast receiver, after start to make a call
Related
I'm facing a Problem, related to my Question: Is it possible to ignore plugged in Headset and still use phone speakers?
I used the same code as in the linked question. The only change here is that I use the PhoneStateListener to intercept when a call is answered and respond to it. This Code is executed, if a Call get's answered:
AudioManager audioManager = (AudioManager) _context.getSystemService(Context.AUDIO_SERVICE);
audioManager.setMode(AudioManager.MODE_IN_CALL);
If I add audioManager.setSpeakerphoneOn(true); to it, the loudspeakers are activated (what I don't want)
Nothing happens if I change the AudioManager Mode from AudioManager.MODE_IN_CALL to AudioManager.MODE_IN_COMMUNICATION
My Problem is, that I can't make an "normal" Phone Call, while my Headset is plugged in.
So far I played around with AudioManager and the setMode() function of it.
Unfortunately, the only thing I managed to do was to make a phone call over the loudspeakers. But this is not the desired goal.
Can anyone help me with this?
I wrote an application which has the capability of hanging up phone calls when they are received. In order to that I'm using the telephony manager and this permission is required:
android.permission.MODIFY_PHONE_STATE
However, this permission makes my app a system app and therefore I won't be able to place it in the play store later.
But I've seen apps in the play store that successfully block incoming calls ("Calls Blacklist" for example).
I wonder, does anyone know what API these apps are using in order to block an incoming call and also allow these apps in the play store ?
Thanks.
You need to make use of Broadcastreceiver class.
and also need to add this line in manifest to get persmission.
<uses-permission android:name="android.permission.READ_PHONE_STATE">
follow this.
http://www.tutorialforandroid.com/2009/01/get-phone-state-when-someone-is-calling_22.html
Make sure TelephonyManager.CALL_STATE_RINGING is only incoming call.
You cannot detect outgoing call state whether it is ringing or answered.
for outgoing there only two states:
TelephonyManager.CALL_STATE_IDLE
&
TelephonyManager.CALL_STATE_OFFHOOK
I'm currently using the READ_PHONE_STATE permission in Android to pause my media player when there's a call, and to resume playback when the call is over. The permission seems to scare a lot of people, so I was wondering if there was an alternative to catching the starting and stopping of a phone call without it. Any help is appreciated. Thanks!
If you want to adjust your audio output in response to something else wanting to perform audio output (e.g., an incoming phone call), look into Android's audio focus support.
READ_PHONE_STATE, as noted, is a bit of a scary permission. Moreover, it only deals with phone calls, and not other things that might need the same capability (e.g., VOIP calls, as AFAIK those don't tie into READ_PHONE_STATE-enabled stuff).
Unfortunately, audio focus is not a substitute for READ_PHONE_STATE. My app has to use both. The standard phone app on my Galaxy S3 I9300/ Android 4.3 doesn't seem to request the audio focus at all. The TelephonyManager class gives you a way to detect the end of the phone call (by sending the CALL_STATE_IDLE state update). The AudioManager doesn't seem to do anything similar, so even if audio focus could be used, it would not be as useful. And, from what I see in the documentation, there doesn't seem to be a narrower permission than READ_PHONE_STATE that would allow the app to read the phone state but not the call information. If I'm wrong about any of this, please correct me.
Unfortunately, audio focus is not a substitute for READ_PHONE_STATE. My app has to use both. The standard phone app on my Galaxy S3 I9300/ Android 4.3 doesn't seem to request the audio focus at all. The TelephonyManager class gives you a way to detect the end of the phone call (by sending the CALL_STATE_IDLE state update). The AudioManager doesn't seem to do anything similar, so even if audio focus could be used, it would not be as useful. And, from what I see in the documentation, there doesn't seem to be a narrower permission than READ_PHONE_STATE that would allow the app to read the phone state but not the call information. If I'm wrong about any of this, please correct me.
I'm working on an app which allows user to take voice notes. For this I'm using the AudioRecorder to constantly obtain audio data from microphone and process it into Mp3.
It all worked great until recently I found out that if I receive/make a call while my app is running in background the other party can't hear me. Clicking on mute/unmute button on dialer screen doesn't do anything - the microphone seems to be disabled until I stop my app.
Now the question is how can I handle this situation? Is my only option is to release AudioRecorder once a voice call is started? I'm perfectly ok if AudioRecorder would just skip the audio data from microphone during the call, but the situation when user can communicate because of the app is unacceptable.
Thanks,
Only 1 app can use the mic at any given time. You might want to use PhoneStateListener so that you can release the recorder when the phone rings or is off the hook.
You can intercept incoming calls using PHONE_STATE action as part of a BroadcastReceiver. Then, in your onReceive function of your receiver, you would check states of the phone:
public void onReceive(Context context, Intent intent) {
String state = intent.getStringExtra(TelephonyManager.EXTRA_STATE);
if(state.equals(TelephonyManager.EXTRA_STATE_RINGING)){
//Phone is ringing
}else if(state.equals(TelephonyManager.EXTRA_STATE_OFFHOOK){
//Call received
}else if (state.equals(TelephonyManager.EXTRA_STATE_IDLE)){
//Call Dropped or rejected
}
}
Do not forget to add the neccessary permissions in your manifest.
Likewise, you can intercept outgoing calls as well. Here is a nice tutorial explaining how to do both.
The rest is about stopping and resuming recorder depending on what you intercept.
What is the difference between calling AudioManager.setRingerMode to calling AudioManager.setStreamMute(AudioManager.STREAM_VOICE_CALL, ...)
What does the documentation mean by "Ringer mode"? I'm pretty sure it is the phone ringer mode. Then how does it differ from calling setStreamMute with STREAM_VOICE_CALL?
If it is not the phone ringer mode, then what is it?
Thanks in advance.
I have never used the audio stream on the android platform, however, based on reading the documentation, I think setRingerMode will affect how the phone reacts to incoming calls. For example, AudioManager.setRingerMode(RINGER_MODE_SILENT) will disable vibrations and sound when an incoming call is received.
However, AudioManager.setStreamMute seems to control more than just the audio stream for phone rings.
From the documentation at http://developer.android.com/reference/android/media/AudioManager.html#STREAM_VOICE_CALL
I think that AudioManager.setRingerMode(RINGER_MODE_SILENT) will act the same way as AudioManager.setStreamMute(STREAM_RING, true).
I think the best way to see what the difference is (nd to see if what I am saying is true) would be to write a small program that tests the two features.