package com.example.webcontentdownload;
import androidx.appcompat.app.AppCompatActivity;
import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Log;
import android.widget.TextView;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.concurrent.ExecutionException;
public class MainActivity extends AppCompatActivity {
public class DownloadTask extends AsyncTask<String, Void, String> {
@Override
protected String doInBackground(String... strings) {
String result = "";
URL url;
HttpURLConnection urlConnection = null;
try {
url = new URL(strings[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 (MalformedURLException e) {
e.printStackTrace();
return "Failed Malformed";
} catch (IOException e) {
e.printStackTrace();
return "Failed IOException";
}
}
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
DownloadTask task = new DownloadTask();
String result = null;
try {
result = task.execute("https://www.google.com/").get();
Log.i("Contents of URL" , result);
} catch (ExecutionException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
**This is my code, I am trying to get the html code of any URL. I have tried the url connection method. I tried to re-install the avd also, sometimes i get Emulator: socketTcpLoopbackClientFor: error: fd 35124 above FD_SETSIZE (32768)
Emulator: emulator: ERROR: AdbHostServer.cpp:102: Unable to connect to adb daemon on port: 5037.
This is displayed in my EVENT LOG. I would very much like your help ** The log I am getting is here.