Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to detect when phone is answered or rejected

Tags:

I managed to prepare an activity when the phone is ringing. Now I need to know how to cancel this activity, when I answer the phone or I reject the call.Do I call EXTRA_STATE_IDLE or EXTRA_STATE_OFFHOOK ?

Any ideas?

Manifest

    <receiver android:name=".IncomingBroadcastReceiver">         <intent-filter>             <action android:name="android.intent.action.PHONE_STATE" />         </intent-filter>     </receiver> 

IncomingBroadcastReceiver java Class

public class IncomingBroadcastReceiver extends BroadcastReceiver {     @Override     public void onReceive(Context context, Intent intent) {         String state = intent.getStringExtra(TelephonyManager.EXTRA_STATE);         // If an incoming call arrives         if (state.equals(TelephonyManager.EXTRA_STATE_RINGING)) { //Did my work } 
like image 348
user1163234 Avatar asked Mar 13 '12 13:03

user1163234


People also ask

How do you know when someone rejects your call?

The best way to know if someone is declining your calls is the number of rings you hear before the call goes to voicemail. As mentioned previously, you won't receive a message or any feedback when a recipient declines your call. But, if you only hear one or two rings, the contact likely declined your call.

Why incoming calls are rejected?

The most common reasons are the flight mode, call barring, call forwarding or call auto-reject.


1 Answers

The above answer is completely wrong in case of outgoing calls. In Android there is no way by which one detect whether the call was actually answered (in case of outgoing calls). The moment you dial a number, the off_hook state is fired. This is one of the drawbacks of Android programming.

like image 178
kkreddy Avatar answered Oct 08 '22 16:10

kkreddy