0

I want to detect the outgoing call when it is answered, I use a BroadcastReciever with the following code:

class OutgoingReceiver : BroadcastReceiver
{
    public override void OnReceive(Context context, Intent intent)
    {
    string number = intent.GetStringExtra(Intent.ExtraPhoneNumber);
    string stateStr = intent.Extras.GetString(TelephonyManager.ExtraState);

       if (stateStr!=null)
       {
           if (stateStr.Equals(TelephonyManager.ExtraStateOffhook))
           { }
           else if (stateStr.Equals(TelephonyManager.ExtraStateIdle))
           { }
        }
     }
}

and use with this code the following permissions:

   <uses-permission android:name="android.permission.READ_PHONE_STATE" />
   <uses-permission android:name="android.permission.PROCESS_OUTGOING_CALLS" />
   <uses-permission android:name="android.permission.READ_PRECISE_PHONE_STATE" />

And also with this receiver on AndroidManifest.xml

<receiver android:name="OutgoingBroadcastReceiver" android:enabled="true" android:exported="true">
        <intent-filter>
            <action android:name="android.intent.action.PHONE_STATE" />
        </intent-filter>
        <intent-filter>
            <action android:name="android.intent.action.NEW_OUTGOING_CALL" />
        </intent-filter>
        <intent-filter>
            <action android:name="android.intent.action.PHONE_STATE_CHANGED" />
        </intent-filter>
    </receiver>

But it is fired only when the outgoing call is start or end. Please, Help me!!

  • increase the priority – Santanu Sur Feb 26 '18 at 20:21
  • @SantanuSur What do you mean by increase the priority? How? –  Feb 26 '18 at 20:49
  • add android:priority = 29449944949 intent filter..and check – Santanu Sur Feb 26 '18 at 20:51
  • @SantanuSur I added this `` but I have error with **Float types not allowed (at 'priority' with value '29449944949')** –  Feb 26 '18 at 21:17
  • @SantanuSur Also I put the priority value with "1000" and test but not fired when the outgoing call is answered –  Feb 26 '18 at 22:51
  • https://stackoverflow.com/questions/13134331/cannot-detect-when-outgoing-call-is-answered-in-android – SushiHangover Feb 26 '18 at 23:09
  • @SushiHangover this link doesn't provide solution, So how can I solve my problem? –  Feb 27 '18 at 18:34
  • What version of Android are you testing this on? BroadcastReceivers in newer versions of Android need to be registered in an Activity, otherwise they are not triggered. – Cheesebaron Feb 28 '18 at 08:59
  • @Cheesebaron I used Android 6 but my problem is that BroadcastReceivers call with me only when call is started and finished, But I need to fired when call is answered. –  Feb 28 '18 at 22:36

0 Answers0