I'm currently learning how to build apps at android studio with udemy course of Rob Percival.
Just reached the point where I want to get info from the internet, I followed the instructions and didn't get the Log I expected (the info from the site).
got an error :
No Network Security Config specified, using platform default
public class ImageDownloader extends AsyncTask<String,Void,String> {
@Override
protected String doInBackground(String... urls) {
String result="";
URL url;
HttpURLConnection urlConnection= null;
try {
url = new URL(urls[0]);
urlConnection=(HttpURLConnection)url.openConnection();
InputStream in=urlConnection.getInputStream();
InputStreamReader reader=new InputStreamReader(in);
int data=reader.read();
while (data != -1){
char current= (char) data;
result += result;
data=reader.read();
}
return result;
}
catch (Exception e) {
e.printStackTrace();
}
return null;
}
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ImageDownloader task=new ImageDownloader();
String result=null;
try {
result=task.execute("http://www.posh24.se/").get();
Log.i("content url", result);
} catch (InterruptedException e) {
e.printStackTrace();
} catch (ExecutionException e) {
e.printStackTrace();
}
}
also I added this line to the Manifest.xml
:
uses-permission android:name="android.permission.INTERNET"
What should I do?