Detecting incoming call on android device with Cordova
<p>I am new to learn to programme for Android. I was looking for a very long plug for the incoming call number. My search attempts were unsuccessful. I decided to create a plugin. I used as an example here are the sources: </p>

<ul>
<li><p><a href="https://github.com/petervojtek/cordova-plugin-signal-strength/blob/master/src/org/apache/cordova/plugin/SignalStrength.java" rel="nofollow noreferrer">https://github.com/petervojtek/cordova-plugin-signal-strength/blob/master/src/org/apache/cordova/plugin/SignalStrength.java</a></p></li>
<li><p><a href="https://github.com/don/cordova-plugin-hello" rel="nofollow noreferrer">https://github.com/don/cordova-plugin-hello</a></p></li>
</ul>

<p>Here's what I came up with:</p>

<pre><code>package org.apache.cordova.plugin;

import android.content.Context;
import android.telephony.PhoneStateListener;
import android.telephony.TelephonyManager;
import org.apache.cordova.CordovaPlugin;
import org.apache.cordova.CallbackContext;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.util.Date;
import android.content.BroadcastReceiver;
import android.content.Intent;


public class SignalStrength extends CordovaPlugin {

    CallStateListener ssListener;
    String Number;

    @Override
    public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {
        if (action.equals("go")) {   
            TelephonyManager tm = (TelephonyManager) cordova.getActivity().getSystemService(Context.TELEPHONY_SERVICE); 
            ssListener = new CallStateListener();
            tm.listen(ssListener, PhoneStateListener.LISTEN_CALL_STATE);
            callbackContext.success(name);
            return true;
        }

        return false;
    }


    class CallStateListener extends PhoneStateListener {

        @Override
        public void onCallStateChanged(int state, String incomingNumber) {
            switch (state) {
                case TelephonyManager.CALL_STATE_RINGING:
                    // called when someone is ringing to this phone
                    String Number= incomingNumber;
                    break;
            }
        }
    }

}
</code></pre>

<p>Manifest:</p>

<pre><code>&lt;uses-permission android:name="android.permission.READ_PHONE_STATE" /&gt;
...
&lt;receiver android:name=".CallReceiver"&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>But unfortunately returns <strong>NULL</strong>
Help me to understand.</p>