NullPointerException on NetworkInfo
<p>I am programming a service that runs when you boot the phone, but you need an Internet connection and connection to send SMS operator.
I wrote a function to <code>ConnectionManager</code> as in other post appears, but I always get the same answer: <code>NullPointerException</code>, when I do the following:</p>

<p>I define <code>cm</code> as <code>ConnectionManager</code> and </p>

<pre><code>NetworkInfo NetInfo = cm.getNetworkInfo();
</code></pre>

<p>Is it not because of this?</p>

<p>How can I fix it?</p>

<p>Sorry if I did not put all the code ...</p>

<p>I have the following in the OnStart () method of a service that is activated by ACTION_BOOT_COMPLETED ...</p>

<pre><code>@ Override
public void OnStart (Intent intent, int start) {

    Context aplCtx = getApplicationContext ();


    IsConnected boolean = false;
    while (! IsConnected) {
        try {
            IsConnected = IsOnline (aplCtx);

        } Catch (Exception e) {
            Log.d (e.toString ());
        }
    }

    .....  
}

private boolean IsOnline (Context ctx) {

    boolean result = false;

    try {
        ConnectivityManager cm = (ConnectivityManager) ctx.getSystemService     (Context.CONNECTIVITY_SERVICE);
        cm.getActiveNetworkInfo NetworkInfo ni = ();

        if (ni! = null) {
           if (ni.getState () == NetworkInfo.State.CONNECTED) {
               result = true;
           }
        }
        return result;
}
</code></pre>

<p>Since this is a background function and after starting the Smartphone, the operating system to force kill the process, before we get an Internet connection. How I can resolve this?,
How do I get the operating system does not kill the process and have an Internet connection to perform the following actions?</p>
