title: Android HTTP Requests Working In Simulator But Not On Wear Device
body: <p>I am making a simple Android Wear app to control my thermostats, and I'm sending POST requests with Volley to control them. Everything works great in the Android Wear simulator (the request works), but, while the app does load on my Moto 360, the volley request gets called but invariably times out.</p>
  
  <p>Why could my volley request be failing on my watch <em>but working on the simulator</em>? Other apps' requests succeed on my watch (for example, the built-in weather app can load up weather data in about 3 seconds). And, the weirdest part: I had the app <em>working</em> (successfully making volley requests) on my watch, and, about a day after I installed it to my watch from Android Studio, it suddenly stopped loading data for no apparent reason.</p>
  
  <p><strong>What I've tried so far:</strong></p>
  
  <ul>
  <li>I have requested the Internet permission in my <code>manifest.xml</code>.</li>
  <li>I have increased the timeout to 30 seconds (see my code below), which didn't change anything.</li>
  <li>I have tried tethering my computer and the simulator to my phone's connection via Bluetooth (to replicate the Bluetooth connection my physical watch has to my phone), and the simulator made the request successfully still (albeit with a two-second delay), ruling out the possibility of Bluetooth being too slow.</li>
  <li>I made sure the API level is low enough for my Marshmallow-running watch (my watch and the app are both API level 23).</li>
  <li>I tried doing a quick test request to Google before the request to the company's servers with my thermostat data, and while the Google request returns the site's HTML code in the simulator, it times out on my watch (thirty seconds after the request is initiated).</li>
  <li>I tried putting some dummy data into the recycler view data should be loaded into, and the dummy data indeed showed up, ruling out that the recycler view is broken.</li>
  <li>I deleted the app from my watch and reinstalled it, and deleted the companion from my phone, reinstalled it, and deleted it again, all to no avail.</li>
  <li>A lengthy chat with Google Support did not produce anything meaningful.</li>
  </ul>
  
  <p><strong>Here's my code (from my main view's adapter):</strong></p>
  
  <pre><code>public void refreshThermostatsRecyclerView(RequestQueue queue) {
      String url = "https://mobile.skyport.io:9090/login"; // login call to the thermostats server Skyport
       Log.w("myApp", "Starting /login call to Skyport"); // this gets called on simulator and watch
       // Request a string response from the provided URL.
       StringRequest stringRequest = new StringRequest(Request.Method.POST, url,
   Response.Listener&lt;String&gt;() {
         @Override
         public void onResponse(String response) {
             // Display the response string.
             Log.w("myApp", "Response is: " + response); // this gets called on the simulator but not the watch
             try {
                 // there's some code to parse the data.
             } catch (JSONException e) {
                  Log.w("myApp", "catching an error parsing the json."); // never gets called.
                  e.printStackTrace();
              }
              }
        }, new Response.ErrorListener() {
              @Override
              public void onErrorResponse(VolleyError error) {
                  Log.w("myApp", "Skyport request didn't work! " + error);  // this always gets called on the watch, with the error being a timeout error (com.Android.Volley.timeouterror) but never gets called in the simulator
              }
          }) {
              @Override
              public Map&lt;String, String&gt; getHeaders() throws AuthFailureError {
                  Map&lt;String, String&gt; m = new HashMap&lt;&gt;();
                  m.put("Referer", "app:/VenstarCloud.swf");
                  // here I put some more headers
                  return m;
              }
  
              @Override
              protected Map&lt;String, String&gt; getParams() throws AuthFailureError {
                  Map&lt;String, String&gt; m = new HashMap&lt;&gt;();
                  m.put("version", "3.0.5");
                  m.put("email", userEmail);
                  m.put("password", userToken);
                  return m;
              }
          };
          // Add the request to the RequestQueue.
          int socketTimeout1 = 30000; // times out 30 seconds after the request starts on the watch
          RetryPolicy policy1 = new DefaultRetryPolicy(socketTimeout1, DefaultRetryPolicy.DEFAULT_MAX_RETRIES, DefaultRetryPolicy.DEFAULT_BACKOFF_MULT);
          stringRequest.setRetryPolicy(policy1);
          queue.add(stringRequest);
      }
  </code></pre>
  
  <p><strong>Which is called from the <code>onCreate()</code> method in my Main Activity with this code:</strong></p>
  
  <pre><code>RequestQueue queue = Volley.newRequestQueue(this);
  refreshThermostatsRecyclerView(queue);
  </code></pre>
  
  <hr>
  
  <p>If you'd like to view the logs created by running this in the simulator and on the watch, they're <a href="https://drive.google.com/file/d/0B4fjCCVHGK_lNGVPWnY4Zk9mSlk/view?usp=sharing">on Google Drive here</a>.</p>
  
  <hr>
  
  <p><strong>Edit 1:</strong> A reboot of my watch fixes the issue temporarily and allows the watch to make HTTP Requests again, but it breaks again once the watch disconnects from Bluetooth, connects to WiFi, disconnects from WiFi, and reconnects to Bluetooth (so it breaks every time I go across my apartment without my phone and then return).</p>
  
  <p><strong>Edit 2:</strong> I switched the volley requests all over to HTTPURLConnection Requests in an Async thread, and the same issues occur as with volley.</p>
  
  <hr>
  
  <p><strong>tl;dr:</strong> My app's Volley requests are working in the simulator but not on my Android Wear watch anymore (though Play Store-downloaded apps' similar requests work), how can I get a volley request to work again on my app on the watch?</p>