I’m new to Android and this is my first application. I’m to connect internet and download JSON from my companies server but unable to get input stream please check this code and provide me assistance.
URL url = new URL("http://www.android.com/");
HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
urlConnection.connect();
InputStream in = new BufferedInputStream(urlConnection.getInputStream());
URL is not the issue I have tested many URL’s. In this code last line gives error. I uses open connectivity (No proxy only firewall) on my development machine and emulators browser is able to access internet.
I have already added
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
parallel to uses-sdk tag in Manifest file.
Here is my working code example..
all you need to Run below code in AsyncTask class and pass your URL and it will returns the response from server.
also make sure you need below Internet permission in your manifest file this way..
Let me know your comment regarding this!!