title: how to identify incoming call and outgoing call in android
body: <p>how to get the events of incoming call and outgoing call in android separately.
  Actually i was trying to develop an application that open on incoming call if number is exist in database and it work OK. but if i call from the device(outgoing call) and if number is exist in database still it open my application.
  i want to restrict to open my application on outgoing call.</p>
  
  <p>my manifest contain i receive incoming call like this:</p>
  
  <pre><code>&lt;receiver android:name=".IncomingCallReceiver" &gt;
      &lt;intent-filter &gt;             
          &lt;action android:name="android.intent.action.PHONE_STATE" /&gt;             
      &lt;/intent-filter&gt;
  &lt;/receiver&gt;
  </code></pre>
  
  <p>IncomingCallReceiver:</p>
  
  <pre><code>MyPhoneStateListener phoneListener=new MyPhoneStateListener(context);
  TelephonyManager telephony = (TelephonyManager)
  context.getSystemService(Context.TELEPHONY_SERVICE);
  telephony.listen(phoneListener,PhoneStateListener.LISTEN_CALL_STATE);
  </code></pre>
  
  <p>MyPhoneStateListener:</p>
  
  <pre><code>public void onCallStateChanged(int state,String incomingNumber){
        switch(state) {
            case TelephonyManager.CALL_STATE_IDLE:
                Log.d("DEBUG", "IDLE");
            break;
            case TelephonyManager.CALL_STATE_OFFHOOK:
                Log.d("DEBUG", "OFFHOOK");                        
                Intent i = new Intent(context, MyMainActivity.class);
                i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                context.startActivity(i);
            break;
            case TelephonyManager.CALL_STATE_RINGING:
                Log.d("DEBUG", "RINGING");
            break;
      }
  }
  </code></pre>
  
  <p>can anyone help me to differentiate outgoing call from incoming call so i'll handle this events.</p>
  
  <p>Thanks in advance.</p>