Read data from WebView (WebKit) or Browser Intent

Problems with WiFi, SQLite ,Bluetooth, WiMax, Proxies, etc...

Read data from WebView (WebKit) or Browser Intent

Postby lokidil » Wed Aug 19, 2009 5:14 am

Hi All,
In my application im trying to load a external url through the browser intent using the code.
Intent i = new Intent(Intent.ACTION_VIEW);
Uri u = Uri.parse("http://xxx.com/");
i.setData(u);
startActivity(i);
and the url is displayed successfully. I also tried using a webview to load the same page.

wView = (WebView) findViewById(R.id.webView);
wView.loadUrl("http://xxx.com/");

But what i need is to read the contents displayed. (ie) Just like reading the page source of a web browser.

Is there any possibility of reading the contents displayed on the android browser or webview. If so please help me with valuable suggetions.


Waiting for your valuable Suggestions,
lokidil
Junior Developer
Junior Developer
 
Posts: 13
Joined: Mon Aug 10, 2009 6:08 am

Top

Postby JamieBennett » Wed Aug 19, 2009 7:44 am

I use the following snippet of code after I have sent a httpPost request to an address. This gets the response which is in the form of a webpage.

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.         // Execute HTTP Post Request  
  2.         try {
  3.                         HttpResponse response = httpClient.execute(httpPost);
  4.                         InputStream is = response.getEntity().getContent();
  5.                         BufferedInputStream bis = new BufferedInputStream(is);
  6.                         ByteArrayBuffer baf = new ByteArrayBuffer(20);
  7.        
  8.                         int current = 0;  
  9.                         while((current = bis.read()) != -1){  
  10.                                 baf.append((byte)current);  
  11.                         }  
  12.          
  13.                         /* Convert the Bytes read to a String. */  
  14.                         responseText = new String(baf.toByteArray());
  15.                        
  16.                 } catch (ClientProtocolException e) {
  17.                         e.printStackTrace();
  18.                 } catch (IOException e) {
  19.                         e.printStackTrace();
  20.                 }
  21.                
  22.                 return responseText;
  23.  
Parsed in 0.032 seconds, using GeSHi 1.0.8.4


But this response also works fine - AndDev answer
JamieBennett
Freshman
Freshman
 
Posts: 4
Joined: Tue Aug 18, 2009 9:22 pm

Top

Return to Networking & Database Problems

Who is online

Users browsing this forum: No registered users and 6 guests