0

I have this called in my Service that creates / updates live card.

URL url = new URL(url1);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();

I am getting Service Not Available. The URL works just fine in browser. I have the internet permission defined in the Manifest. What might be going on and what might be the fix?

sivag1
  • 4,734
  • 3
  • 32
  • 35
  • When you say it works fine in the browser, do you mean the Glass browser or your computer's browser? Have you made sure that your Glass device has an internet connection (either wifi or paired with MyGlass) when you try to run this code? – Tony Allevato Dec 09 '13 at 18:55
  • It is in computer browser. Do you think the Rest server is not accepting connections from Glass? If so, is there a workaround? – sivag1 Dec 09 '13 at 22:23
  • It's a bit hard to tell what could be happening with so little code, so you might like to post more of your code and possibly manifest. I had no trouble getting Glass to make network calls with just a standard Android AsyncTask piece of code copied from another Android project. In the manifest I included: so I wonder if you are missing one of these. Did you try running your same code on another Android device? – Darren Dec 10 '13 at 01:55

1 Answers1

1

Ok, able to resolve this. Thanks to @Darren. Problem was, I was not using a new Thread or Async Task. Glass did not give the usual error that comes in Android like Network in Main thread exception. Instead gave weird exception like Service Not Available or sometimes just null.

Having the connection initiation in a new Thread resolved this.

sivag1
  • 4,734
  • 3
  • 32
  • 35