title: Getting the direction is Incoming or Outgoing
body: <p>In order to be a default phone app, It is mandatory to implement <code>InCallService</code> along with <code>meta-data</code> tags in the manifest and using <code>CALL_PHONE</code> permission.</p>
  
  <p><strong>What i have done so far :</strong></p>
  
  <p>Manifest.xml </p>
  
  <pre><code>&lt;uses-permission android:name="android.permission.CALL_PHONE" /&gt;
  
  &lt;service
              android:name=".InCallServiceImplementation"
              android:enabled="true"
              android:exported="true"
              android:permission="android.permission.BIND_INCALL_SERVICE"&gt;
              &lt;meta-data
                  android:name="android.telecom.IN_CALL_SERVICE_UI"
                  android:value="true" /&gt;
              &lt;meta-data
                  android:name="android.telecom.IN_CALL_SERVICE_RINGING"
                  android:value="true" /&gt;
  
              &lt;intent-filter&gt;
                  &lt;action android:name="android.telecom.InCallService" /&gt;
              &lt;/intent-filter&gt;
   &lt;/service&gt;
  </code></pre>
  
  <p>Having been asked for default, having the CALL_PHONE permission granted by user too. 
  Below is my InCallServiceImplementation.java which extends InCallService </p>
  
  <pre><code>    @Override
      public void onCallAdded(Call call)
      {
          super.onCallAdded(call);
          Log.d("InCallService :", "Added a new call.. \n");
          new OngoingCall().setCall(call);
  
          Log.d("InCallService :", "FOUND DIRECTION FOR INCOMING :" + IsInComingCall + ".. \n");
  
          if (IsInComingCall)
          {
              // START ACTIVITY FOR INCOMING CALL
              //IncomingCallActivity.start(this, call);
          }
          else
          {
              // START ACTIVITY FOR OUTGOING CALL
              //DialerActivity.start(this, call);
          }
      }
  
      @Override
      public void onCallRemoved(Call call)
      {
          super.onCallRemoved(call);
          Log.d("InCallService :", "Call is removed.. \n");
          new OngoingCall().setCall(null);
      }
  </code></pre>
  
  <p>And below is my OngoingCall.java class</p>
  
  <pre><code>    private Object callback = new Call.Callback() 
      {
          @Override
          public void onStateChanged(Call call, int newState) {
              super.onStateChanged(call, newState);
              state.onNext(newState);
          }
      };
  
      public final void setCall(@Nullable Call value) 
      {
          if (call != null) 
          {
              call.unregisterCallback((Call.Callback)callback);
          }
  
          if (value != null) 
          {
              value.registerCallback((Call.Callback)callback);
              state.onNext(value.getState());
          }
  
          call = value;
      }
  
      public void answer() 
      {
          assert call != null;
          call.answer(VideoProfile.STATE_AUDIO_ONLY);
      }
  
      public void hangup() 
      {
          assert call != null;
          call.disconnect();
      }
  </code></pre>
  
  <p><strong>How it is working :</strong> 
  It is working fine if i makes dial or call from My App, Or even if dial from manufacturer phone app, it launches my <code>DialerActivity</code> if the <code>if-else</code> is removed from function <code>onCallAdded</code></p>
  
  <p><strong>What is the problem then :</strong></p>
  
  <p>Even if any incoming call is coming it is still showing <code>DialerActivity</code> which shows outgoing call is in progress Screen. I have 2 different activities for incoming and outgoing call. </p>
  
  <p><strong>What resolution i am looking for :</strong> </p>
  
  <p>How can i find is the call is incoming or outgoing, the call direction. So that appropriate layout can be presented to the user. </p>
  
  <p><strong>What are the efforts taken for studying or search :</strong></p>
  
  <p>I always found it very hard to understand what google documentation is meant for? </p>
  
  <p>Found it here <a href="https://developer.android.com/reference/android/telecom/Call.Details.html#getCallDirection()" rel="nofollow noreferrer">Call.Details</a> the direction can be taken. I searched a lot and again found <a href="https://developer.android.com/guide/topics/connectivity/telecom/selfManaged" rel="nofollow noreferrer">Build a Calling App</a> which lacs many things of implementation. Just some overview and some incomplete samples shown with a lot of theory. I found <a href="https://github.com/arekolek/simple-phone" rel="nofollow noreferrer">Simple Phone</a> but it is developed in kotlin. The same project is in java named as <a href="https://github.com/Abror96/CustomPhoneDialer" rel="nofollow noreferrer">Custom Phone Dialer</a> which has not implemented the direction. Nor i found any proper and step by step guides from google documentation. If a developer tries to read their sample programs, many variables and functions are missing, its useless to read and spend a lot time over studying it. </p>