gettingalongfamously asked: Hey James, I'm new to app dev and decided to see how easy/difficult it would be to port my fx addon (see zigratdotcom) to an app. I found your "view web source" app and tried to download it to peek at your work but since I've no phone associated with the account, I was denied (argh!!). Can you tell me how I could take a look at what you did or point me to another helpful resource? I have been browsing android dev guide but I prefer working backwards, so to speak. Thx, Jennifer
View web source is rather simple to how it works. Its basically made up of two functions:
public static InputStream getInputStreamFromUrl(String url) {
InputStream content = null;
try {
HttpClient httpclient = new DefaultHttpClient();
HttpResponse response = httpclient.execute(new HttpGet(url));
content = response.getEntity().getContent();
} catch (Exception e) {
Log.e(“ViewSource”, “Network exception”, e);
}
return content;
}
This method takes the url of the website you want to view, the url is then executed and it returns an inputstream containing the content of the website.
Now you have the input stream, you need to extract the contents of the website as a string.
private String inputStreamToString(InputStream is) {
String line = “”;
StringBuilder total = new StringBuilder();
// Wrap a BufferedReader around the InputStream
BufferedReader rd = new BufferedReader(new InputStreamReader(is));
// Read response until the end
while ((line = rd.readLine()) != null) {
total.append(line);
}
// Return full string
return total.toString();
}
This takes the input stream and reads it line by line to return a response.
Once you have this string , you can work on your integrating it into your application :)
Best of luck, if you need anymore pointers feel free to ask