title: Android Studio/Java - Trouble with URLConnection and Receiver
body: <p>I am attempting to get when a file has last been modified on a server using the HttpUrlConnection class. If it has been modified more recently than a local file, the program will proceed with a download. However, I am having difficulties - there appears to be a problem with calling the getLastModified method. </p>
  
  <pre><code>    public class downloadReceiver extends BroadcastReceiver {
  
          private Context context;
  
          @Override
          public void onReceive(Context c, Intent i) {
  
              long localUpdate;
              long remoteUpdate = 20;
              File dbFile = new File(c.getFilesDir(), "bk.db");
  
              localUpdate = dbFile.lastModified();
              try {
                  Log.i("passing", "entering try");
                  URL url = new URL("http://midamcorp.com/bk.php");
                  HttpURLConnection con = (HttpURLConnection) url.openConnection();
                  Log.i("passing", "con");
                  Log.i("Database modified", "" + con.getLastModified());
                  remoteUpdate = con.getLastModified();
  
                  con.disconnect();
  
              } catch (Exception e) {Log.e("URL Exception:", "" + e.getMessage());}
       if(remoteUpdate &gt; localUpdate) {
          DownloadManager manager = (DownloadManager) c.getSystemService(Context.DOWNLOAD_SERVICE);
          Log.e("passing", "onReceive");
          DownloadManager.Request request = new DownloadManager.Request(Uri.parse("http://midamcorp.com/bk.php"));
          request.setMimeType("application/octet-stream");
          manager.enqueue(request);
      } else {Log.i(this.getClass().toString(), "No update necessary" + remoteUpdate + " " + localUpdate); }
  
          }
  
  
      }
  </code></pre>
  
  <p>The remoteUpdate value is never changed, an Exception message is never logged, and Studio logs "entering try" and "con" successfully, but then skips to logging the "No update necessary" statement.</p>
  
  <pre><code>04-08 12:02:30.096 2293-2293/midamcorp.com.burgerkingapp I/passing: entering try
  04-08 12:02:30.159 2293-2293/midamcorp.com.burgerkingapp I/passing: con
  04-08 12:02:30.166 2293-2293/midamcorp.com.burgerkingapp I/class midamcorp.com.burgerkingapp.downloadReceiver: No update necessary20 1460134911000
  </code></pre>
  
  <p>Why might this be?</p>
  
  <p>Thanks so much!</p>