create an async task for online js parsing
This commit is contained in:
@ -0,0 +1,31 @@
|
||||
package com.cradle.iitc_mobile.async;
|
||||
|
||||
import android.os.AsyncTask;
|
||||
|
||||
import com.cradle.iitc_mobile.IITC_Mobile;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.util.Scanner;
|
||||
|
||||
/*
|
||||
* this class parses the content of an web page.
|
||||
* since network operations shouldn't be done on main UI thread
|
||||
* we use an async task for this.
|
||||
*/
|
||||
public class UrlContentToString extends AsyncTask<URL, Integer, String> {
|
||||
|
||||
@Override
|
||||
protected String doInBackground(URL... urls) {
|
||||
String js = "";
|
||||
URL url = urls[0];
|
||||
try {
|
||||
js = new Scanner(url.openStream(), "UTF-8").useDelimiter("\\A")
|
||||
.next();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return js;
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user