title: Getting connection timeout exception in android while trying to get response from server
body: <p>I have developed a android app which connect to server and access xml from server using url. I am Using HttpUrlConncetion to connect. I have written this connection code in a jar file and My app is using this jar to connect to server.This app is working properly when i am using emulator but when i install this app on my mobile then it throw exception.</p>
  
  <p>I have added intenet permission in manifest file.</p>
  
  <pre><code>&lt;uses-permission android:name="android.permission.INTERNET" /&gt;
  </code></pre>
  
  <p>Exception is </p>
  
  <pre><code>Connection timed out 
  org.apache.harmony.luni.platform.OSNetworkSystem.connect(Native Method)
  dalvik.system.BlockGuard$WrappedNetworkSystem.connect(BlockGuard.java:388)
  org.apache.harmony.luni.net.PlainSocketImpl.connect(PlainSocketImpl.java:236)
  org.apache.harmony.luni.net.PlainSocketImpl.connect(PlainSocketImpl.java:470)
  java.net.Socket.connect(Socket.java:1055)
  org.apache.harmony.luni.internal.net.www.protocol.http.HttpConnection.&lt;init&gt;           (HttpConnection.java:106)
  org.apache.harmony.luni.internal.net.www.protocol.http.HttpConnection.&lt;init&gt;   (HttpConnection.java:79)org.apache.harmony.luni.internal.net.www.protocol.http.HttpConnection$Address.connect(HttpConnection.java:353)org.apache.harmony.luni.internal.net.www.protocol.http.HttpConnectionPool.get(HttpConnectionPool.java:120)org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl.getHttpConnection
  (HttpURLConnectionImpl.java:316)org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl.makeConnection
  
  (HttpURLConnectionImpl.java:298)
  org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl.connect
  
  (HttpURLConnectionImpl.java:236)
  com.tracking.jar.XmlDownLoader.openConnection(XmlDownLoader.java:46)
  com.tracking.jar.XmlDownLoader.downLoadXml(XmlDownLoader.java:18)
  com.tracking.jar.BusDetails.getProviderRouteBeanList
  
  (BusDetails.java:179)
  com.vehicletracking.GetProviderRouteBeanListAsyncTask.doInBackground
  
  (GetProviderRouteBeanListAsyncTask.java:17)
  com.vehicletracking.GetProviderRouteBeanListAsyncTask.doInBackground
  
  (GetProviderRouteBeanListAsyncTask.java:1)
  android.os.AsyncTask$2.call(AsyncTask.java:216)
  java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:337)
  java.util.concurrent.FutureTask.run(FutureTask.java:169)
  java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1119)
  java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:612)
  java.lang.Thread.run(Thread.java:1052)
  </code></pre>
  
  <p>My mobile is rooted and i have in install app call blocker app which block incoming and out going call.</p>
  
  <p>My connection code is:</p>
  
  <pre><code>public String downLoadXml(String urlString) throws Exception{
      urlString = urlString.replace(" ", "%20");
      String xfStr = "";
      HttpURLConnection httpConn = null;
      try{
          httpConn = openConnection(urlString);
          InputStream in = httpConn.getInputStream();
          InputStreamReader isr = new InputStreamReader(in);
          BufferedReader br = new BufferedReader(isr);
          String str =null;
  
          while((str = br.readLine())!= null){
              xfStr = xfStr + str;
          }
      }catch(Exception e){
          throw e;
      }
      finally{
          if(httpConn!=null){
              httpConn.disconnect();
          }
      }
      return xfStr;
  }
  
  private HttpURLConnection openConnection(String urlString) throws IOException{
      URL url  = new URL(urlString);
      HttpURLConnection httpConn = null;
      httpConn = (HttpURLConnection) url.openConnection();
      httpConn.setAllowUserInteraction(false);
      httpConn.setInstanceFollowRedirects(false);
      httpConn.setRequestMethod("GET");
      httpConn.setConnectTimeout(60000);
      httpConn.connect();
      return httpConn;
  }
  </code></pre>