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 }
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.
The most common reasons are the flight mode, call barring, call forwarding or call auto-reject.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With