Hallo Ich versuche, Webseiten HTML-Inhalt in meinem Logcat herunterladen, so dass ich zukünftig spezifische Informationen in der Zukunft auswählen kann. Aber bevor ich das machen kann, möchte ich testen, ob ich die Website zuerst kontaktieren kann. Zur Zeit bekomme ich keinen Fehler, aber ich bekomme auch keinen Kontext.Android Download-Website HTML-Inhalt
// Die öffentliche Klasse habe ich
public class DownloadTsk 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 += current;
data = reader.read();
}
return result;
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
}
// onCreate Methode
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
DownloadTsk task = new DownloadTsk();
String result = null;
try {
result = task.execute("http://www.posh24.com/celebrities").get();
Log.i("Content", result);
} catch (InterruptedException e) {
e.printStackTrace();
} catch (ExecutionException e) {
e.printStackTrace();
}
// Aktuelle Ergebnis
Content: <!DOCTYPE html>
<html>
<head>