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
View Web Source came 14th in .net magazine’s top 20 mobile applications for web devs. Shame no screenshot or mention of my name but oh well, no complaints!
.net Magazine #203 Page 50:
Most web users don’t care about source code, so it’s perfectly understandable that mobile browsers don’t shoehorn a View Source options into streamlined user interfaces. For developers, though, the ability to peek under teh hood is of paramount importance. On Android, View Web Source enables you to load the source of any URL of your choosing, search the resulting text, and also copy and paste the code.
View Web Source 1.5 Released
Released a new version of my View Web Source application. This update cleans the code up a fair bit most noticeably by adding progress dialogues when downloading the source and also, and more importantly, I’ve added View Web Source to the share feature in the Android Browser.
This means if you are browsing some page, and you decide you want to view the source of the site, you can click share page then share with View Web Source. My app will then download the source of the page for you :)
Hope you guys like the update, let me know if there are any other changes you want made
Some Statistics…
Well its been a while now since I’ve published my applications on the app market so I thought I’d publish some stats on how I’m doing so far :)
View Web Source
Downloads: 244 - Active Installs: 159 (65%)
Ratings: 3 - Stars 4 1/2 stars
Drinking Games
Downloads: 36746 - Active Installs: 30208 (82%)
Rating: 85 - Stars: 4 stars
Drinking Games Pro
Downloads 45 - Active Installs: 41 (91%)
Rating: 1 - Stars: 5 stars
I’m pretty happy with that :)