title: Network call not happening from a thread in a broadcast receiver
body: <p>Im a beginnner of android and im trying to build an app that recognizes a missed call and sends the number to be stored in a remote mysql database. The app is able to recognize missed calls but the network calls are not happening. I am not able to run this app in the emulator and so im using a device everytime i make changes to this app.</p>
  
  <p>This is my code</p>
  
  <pre><code>    package com.example.missedcallverify;
  
      import java.io.BufferedReader;
      import java.io.InputStream;
      import java.io.InputStreamReader;
      import java.util.ArrayList;
  
      import org.apache.http.HttpEntity;
      import org.apache.http.HttpResponse;
      import org.apache.http.NameValuePair;
      import org.apache.http.client.HttpClient;
      import org.apache.http.client.entity.UrlEncodedFormEntity;
      import org.apache.http.client.methods.HttpPost;
      import org.apache.http.impl.client.DefaultHttpClient;
      import org.apache.http.message.BasicNameValuePair;
  
      import com.loopj.android.http.AsyncHttpClient;
      import com.loopj.android.http.AsyncHttpResponseHandler;
      import com.loopj.android.http.RequestParams;
  
      import android.content.BroadcastReceiver;
      import android.content.Context;
      import android.content.Intent;
      import android.os.Bundle;
      import android.telephony.TelephonyManager;
      import android.util.Log;
      import android.widget.Toast;
  
      public class IncommingCallReceiver extends BroadcastReceiver
      {
  
           static boolean ring=false;
           static boolean callReceived=false;
           static String callerPhoneNumber;
  
  
           @Override
           public void onReceive(final Context mContext, Intent intent)
           {
  
                  // Get the current Phone State
                 String state = intent.getStringExtra(TelephonyManager.EXTRA_STATE);
  
                 if(state==null)
                     return;
  
                 // If phone state "Rininging"
                 if(state.equals(TelephonyManager.EXTRA_STATE_RINGING))
                 {           
                           ring =true;
                          // Get the Caller's Phone Number
                          Bundle bundle = intent.getExtras();
                          callerPhoneNumber= bundle.getString("incoming_number");
                          Toast.makeText(mContext, callerPhoneNumber, Toast.LENGTH_LONG).show();
                   }
  
  
  
                  // If incoming call is received
                 if(state.equals(TelephonyManager.EXTRA_STATE_OFFHOOK))
                  {
                         callReceived=true;
                         Toast.makeText(mContext, callerPhoneNumber+"hello ", Toast.LENGTH_LONG).show();
                   }
  
  
                  // If phone is Idle
                 if (state.equals(TelephonyManager.EXTRA_STATE_IDLE))
                 {
                           // If phone was ringing(ring=true) and not received(callReceived=false) , then it is a missed call
                    if(ring==true&amp;&amp;callReceived==false)
                    {
                             Toast.makeText(mContext, "It was A MISSED CALL from : "+callerPhoneNumber, Toast.LENGTH_LONG).show();
                             final Intent intnt = new Intent(mContext,
                                      MyService.class);
                              intnt.putExtra("callerPhoneNumber", callerPhoneNumber);
                              mContext.startService(intnt);
  
                    }
               }
        }
  
  
  
      }
  </code></pre>
  
  <p>MyService.java</p>
  
  <pre><code>package com.example.missedcallverify;
  
  import java.io.InputStream;
  import java.util.ArrayList;
  
  import org.apache.http.HttpEntity;
  import org.apache.http.HttpResponse;
  import org.apache.http.NameValuePair;
  import org.apache.http.client.HttpClient;
  import org.apache.http.client.entity.UrlEncodedFormEntity;
  import org.apache.http.client.methods.HttpPost;
  import org.apache.http.impl.client.DefaultHttpClient;
  import org.apache.http.message.BasicNameValuePair;
  
  import android.app.Service;
  import android.content.Intent;
  import android.os.IBinder;
  import android.util.Log;
  import android.widget.Toast;
  
  public class MyService extends Service {
  
    String callerPhoneNumber;
  
    @Override
    public void onCreate() {
      // TODO Auto-generated method stub
      super.onCreate();
  
  
    }
  
    @Override
    public IBinder onBind(Intent intent) {
      // TODO Auto-generated method stub
  
      return null;
    }
  
    @Override
    public int onStartCommand(Intent intent, int flags, int startId) {
      // TODO Auto-generated method stub
  
      callerPhoneNumber = intent.getStringExtra(callerPhoneNumber);
      Toast.makeText(this, "Service started", Toast.LENGTH_LONG).show();
      new Thread(){
        @Override
        public void run() {
          // TODO Auto-generated method stub
          super.run();
          String result = "";
          InputStream is = null;
          ArrayList&lt;NameValuePair&gt; nameValuePairs = new ArrayList&lt;NameValuePair&gt;();
          nameValuePairs.add(new BasicNameValuePair("no", callerPhoneNumber));
          try{
                HttpClient httpclient = new DefaultHttpClient();
                HttpPost httppost = new HttpPost("http://mywebsite.in/confirm_user.php");
                httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
                HttpResponse response = httpclient.execute(httppost);
                HttpEntity entity = response.getEntity();
                is = entity.getContent();
          }catch(Exception e){
          Log.e("log_tag", "Error in http connection "+e.toString());
          }       
        }
      }.start();
      return super.onStartCommand(intent, flags, startId);
    }
  
  }
  </code></pre>
  
  <p>Manifest.xml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.example.missedcallverify"
      android:versionCode="1"
      android:versionName="1.0" &gt;
  
      &lt;uses-sdk
          android:minSdkVersion="8"
          android:targetSdkVersion="21" /&gt;
       &lt;uses-permission android:name="android.permission.READ_PHONE_STATE" /&gt;
       &lt;uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /&gt;
       &lt;uses-permission android:name="android.permission.INTERNET" /&gt;
  
      &lt;application
          android:allowBackup="true"
          android:icon="@drawable/ic_launcher"
          android:label="@string/app_name"
          android:theme="@style/AppTheme" &gt;
  
          &lt;service
              android:name=".MyService"
              android:enabled="true" /&gt;
  
          &lt;!-- Register the Broadcast receiver  --&gt;
          &lt;receiver android:name=".IncommingCallReceiver" android:enabled="true"&gt; 
              &lt;intent-filter&gt;
                      &lt;action android:name="android.intent.action.PHONE_STATE" /&gt; 
                  &lt;/intent-filter&gt;
             &lt;/receiver&gt;
      &lt;/application&gt;
  
  &lt;/manifest&gt;
  </code></pre>
  
  <p>I get the toast saying It was a missed call from: number. However the network call is not happening and im unable to see the logs too. I dint see even service started message. Please help me</p>