Created
March 26, 2021 18:53
-
-
Save nuriyevn/90649e07828fe92150979c2ded321c6f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.example.guesscelebrities; | |
import androidx.appcompat.app.AppCompatActivity; | |
import android.os.AsyncTask; | |
import android.os.Bundle; | |
import android.telephony.euicc.DownloadableSubscription; | |
import android.util.Log; | |
import java.io.InputStream; | |
import java.io.InputStreamReader; | |
import java.net.HttpURLConnection; | |
import java.net.URL; | |
public class MainActivity extends AppCompatActivity { | |
public class DownloadTask 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 + current; | |
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); | |
DownloadTask task = new DownloadTask(); | |
String result = null; | |
try{ | |
result = task.execute("https://www.usmagazine.com/celebrities/a/").get(); | |
Log.i("Contents of URL" , result); | |
} | |
catch (Exception e) { | |
e.printStackTrace(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment