title: SocketTimeOutException when using okhttp android in broadcast receiver
body: <p>I need to send data to server for every 3 minutes. I am using alarm Manager to trigger for every 3 minutes and I am using asynctask in broadcast receiver but I am getting error as SocketTimeoutException in okhttp. How to solve this. I checked method in okhttp but I can't find a method mOkHttpClient.setConnectTimeout(REQ_TIMEOUT, TimeUnit.SECONDS);</p>
  
  <p>Here is code</p>
  
  <pre><code> public class AlarmReceiver extends BroadcastReceiver {
  private Context context;
  private VALERTApplication mValertApplication;
  
  @Override
  public void onReceive(Context context, Intent intent) {
      this.context=context;
      new DownloadTask()
                  .execute();
  }
  
    private class DownloadTask extends AsyncTask&lt;String, Void, String&gt; {
      @Override
      protected String doInBackground(String... params) {
          // do your request in here so that you don't interrupt the UI thread
          try {
              RequestBody formBody = new FormBody.Builder()
                      .add("userUUID", "281FDACE- 6400-4091-8BD1-F6CC2E8F64AB")
                      .add("readingTime", "182525")
                      .add("readingdate", "20160612")
                      .add("readingValue", "12")
                      .add("timezone", "EST")
                      .add("readingType", "9")
                      .build();
  
              OkHttpClient client = new OkHttpClient();
              Request request = new Request.Builder()
                      .url("https://apps.vocare.com/api/index.cfm?endpoint=/readings")
                      .post(formBody)
                      .build();
  
              Response response = client.newCall(request).execute();
              return response.body().string();
  
          } catch (IOException e) {
              return "Unable to retrieve data. URL may be invalid.";
          }
      }
      @Override
      protected void onPostExecute(String result) {
              Log.e("result",result);
          }
      }
  </code></pre>
  
  <p>}</p>
  
  <p>I am getting error as</p>
  
  <pre><code>  java.net.SocketTimeoutException: SSL handshake timed out
    at   com.android.org.conscrypt.NativeCrypto.SSL_do_handshake(Native Method)
    at com.android.org.conscrypt.OpenSSLSocketImpl.startHandshake(OpenSSLSocketImpl.java:318)
    at   okhttp3.internal.io.RealConnection.connectTls(RealConnection.java:239)
    at okhttp3.internal.io.RealConnection.establishProtocol(RealConnection.java:196)
    at okhttp3.internal.io.RealConnection.buildConnection(RealConnection.java:171)
    at okhttp3.internal.io.RealConnection.connect(RealConnection.java:111)
    at okhttp3.internal.http.StreamAllocation.findConnection(StreamAllocation.java:187)
    at okhttp3.internal.http.StreamAllocation.findHealthyConnection(StreamAllocation.java:123)
    at okhttp3.internal.http.StreamAllocation.newStream(StreamAllocation.java:93)
    at okhttp3.internal.http.HttpEngine.connect(HttpEngine.java:296)
    at okhttp3.internal.http.HttpEngine.sendRequest(HttpEngine.java:248)
    at okhttp3.RealCall.getResponse(RealCall.java:243)
    at okhttp3.RealCall$ApplicationInterceptorChain.proceed(RealCall.java:201)
    at okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.java:163)
    at okhttp3.RealCall.execute(RealCall.java:57)
    at com.vcare.services.AlarmReceiver$DownloadTask.doInBackground(AlarmReceiver.java:76)
    at com.vcare.services.AlarmReceiver$DownloadTask.doInBackground(AlarmReceiver.java:48)
    at android.os.AsyncTask$2.call(AsyncTask.java:292)
    at java.util.concurrent.FutureTask.run(FutureTask.java:237)
    at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
    at java.lang.Thread.run(Thread.java:818)
    06-14 16:48:44.259 13881-13881/com.vocare E/result: Unable to retrieve data. URL may be invalid.
  </code></pre>