title: Cordova Plugin to identify incoming call number in android?
body: <p>I am trying to get the incoming call number from my cordova android plugin. Able to get the Phone State using TELEPHONYMANGER.PHONE_STATE_CHANGED. But unable to get the incoming call number. BroadcastReceiver's Intent provides the option to get the incoming call number. But BroadcastReceiver's onReceive function is not triggered. Please help.</p>
  
  <pre><code>package io.infonion.calldetail;
  
  import org.apache.cordova.CordovaPlugin;
  import org.apache.cordova.CallbackContext;
  import android.support.v4.content.LocalBroadcastManager;
  import org.apache.cordova.PluginResult;
  import android.content.Context;
  import android.widget.Toast;
  import android.telephony.PhoneStateListener;
  import android.content.Intent;
  import android.content.IntentFilter;
  import android.telephony.TelephonyManager;
  import android.content.BroadcastReceiver;
  import android.os.Bundle;
  import android.util.Log;
  import org.json.JSONException;
  import org.json.JSONArray;
  
  import org.json.JSONArray;
  import org.json.JSONException;
  import org.json.JSONObject;
  public class CallDetail extends CordovaPlugin {
      CallStateListener listener;
      IntentFilter intentFilter;
      Context maincontext;
          public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {
              Toast.makeText(cordova.getActivity().getApplicationContext(), "first", Toast.LENGTH_LONG).show();
              if (listener == null) {
                  listener = new CallStateListener();
                  listener.setCordovaContext(cordova.getActivity().getApplicationContext());
                  listener.setCallbackContext(callbackContext);
                  Toast.makeText(cordova.getActivity().getApplicationContext(), "fourth", Toast.LENGTH_LONG).show();
                  intentFilter = new IntentFilter() ;
                  intentFilter.addAction(TelephonyManager.ACTION_PHONE_STATE_CHANGED);
                  LocalBroadcastManager.getInstance(super.webView.getContext()).registerReceiver(listener,intentFilter);
                  //registerReceiver(listener, intentFilter);
                  Toast.makeText(cordova.getActivity().getApplicationContext(), "fifth", Toast.LENGTH_LONG).show();
              }
              return true;
          }
  
  
  
  
      }
       class CallStateListener extends BroadcastReceiver {
  
          private CallbackContext callbackContext;
         private Context cordovaContext;
  
              public void setCallbackContext(CallbackContext callbackContext) {
                  Toast.makeText(cordovaContext, "third", Toast.LENGTH_LONG).show();
                  this.callbackContext = callbackContext;                
              }
  
              public void setCordovaContext(Context cordovaContext) {
                  Toast.makeText(cordovaContext, "second", Toast.LENGTH_LONG).show();
                  this.cordovaContext = cordovaContext;                
              }
  
  
  
  
              @Override
              public void onReceive(final Context context, Intent intent) {
                  String act=intent.getAction();
                  String number="";
                  Toast.makeText(cordovaContext, "Sixth", Toast.LENGTH_LONG).show();
  
                  if(intent.getAction().equals("TelephonyManager.ACTION_PHONE_STATE_CHANGED")){
  
                      String state = intent.getStringExtra(TelephonyManager.EXTRA_STATE);
                      Toast.makeText(cordovaContext, state, Toast.LENGTH_LONG).show();
                      if(state.equals(TelephonyManager.EXTRA_STATE_OFFHOOK)){
                          //  Log.d(TAG, "Inside Extra state off hook");
                       number = intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER);
                          Toast.makeText(cordovaContext, "EXTRA_STATE_OFFHOOK", Toast.LENGTH_LONG).show();
                          //   Log.e(TAG, "outgoing number : " + number);              
                      }       
  
                      else if (state.equals(TelephonyManager.EXTRA_STATE_RINGING)){   
                          //   Log.e(TAG, "Inside EXTRA_STATE_RINGING");
                           number = intent.getStringExtra(TelephonyManager.EXTRA_INCOMING_NUMBER);
                          Toast.makeText(cordovaContext, "RINGING", Toast.LENGTH_LONG).show();
                          //   Log.e(TAG, "incoming number : " + number);
                      }
                      else if(state.equals(TelephonyManager.EXTRA_STATE_IDLE)){
                          Toast.makeText(cordovaContext, "EXTRA_STATE_IDLE", Toast.LENGTH_LONG).show();
                          //  Log.d(TAG, "Inside EXTRA_STATE_IDLE");
                      }   
  
                      PluginResult result = new PluginResult(PluginResult.Status.OK, number);
                      result.setKeepCallback(true);
                      callbackContext.sendPluginResult(result);
                  } 
  
  
  
  
  
              }
          }
  </code></pre>