0

I have have a WebView that show me a webpage that include an URL that contains a RSS feed, how can i store the URL before the page is loaded?

Example page:

This page is your personal news channel

URL of RSS channel: http://domain.com/news/feed.php?user_id=150&hash=7cde58a3f234929385068d3e64c13e

%%%%%EDIT CODE TO ENTER THE PAGE%%%%

 public class ilias extends Activity {

 WebView webView;

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        webView = (WebView)findViewById(R.id.webview);

        BufferedReader bufferedReader = null;
        HttpClient httpClient = new DefaultHttpClient();
        HttpPost request = new HttpPost("http://www.ilias.de/docu/login.php?client_id=docu");
        List<NameValuePair> postParameters = new ArrayList<NameValuePair>();
        postParameters.add(new BasicNameValuePair("username", "stacked")); //this username 
        postParameters.add(new BasicNameValuePair("password", "overflow"));//works


  try {
   UrlEncodedFormEntity entity = new UrlEncodedFormEntity(postParameters);
         request.setEntity(entity);

         HttpResponse response= httpClient.execute(request);

   bufferedReader = new BufferedReader(
           new InputStreamReader(response.getEntity().getContent()));
   StringBuffer stringBuffer = new StringBuffer("");
   String line = "";
   String LineSeparator = System.getProperty("line.separator");
   while ((line = bufferedReader.readLine()) != null) {
    stringBuffer.append(line + LineSeparator); 
   }
   bufferedReader.close();

   Toast.makeText(ilias.this, 
     "Finished", 
     Toast.LENGTH_LONG).show();

   String webData = stringBuffer.toString();

   webView.setWebViewClient(new WebViewClient()); 
   webView.loadDataWithBaseURL("http://www.ilias.de/docu/",webData,"text/html","UTF-8","about:blank");
   String postData = "username=stacked&password=overflow";
   String url = "http://www.ilias.de/docu/login.php?client_id=docu";

  webView.postUrl(url, EncodingUtils.getBytes(postData, "base64"));

  webView.loadUrl("http://www.ilias.de/docu/ilias.php?col_side=left&block_type=pdnews&cmd=showFeedUrl&cmdClass=ilpdnewsblockgui&cmdNode=i7:db:le&baseClass=ilPersonalDesktopGUI");

  } catch (ClientProtocolException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
   Toast.makeText(ilias.this, 
     e.toString(), 
     Toast.LENGTH_LONG).show();
  } catch (IOException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
   Toast.makeText(ilias.this, 
     e.toString(), 
     Toast.LENGTH_LONG).show();
  }finally{
   if (bufferedReader != null){
    try {
     bufferedReader.close();
    } catch (IOException e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
    }
   }
  }

    }
}
7
  • So the webpage includes the url and not the app itself, or the code? Commented Oct 20, 2011 at 13:39
  • the url is on the webpage. ı need to parse it and then use it in my app Commented Oct 20, 2011 at 14:22
  • You need to use a HTML parser such as JSOUP and parse the url text using the tag. Commented Oct 20, 2011 at 14:38
  • What is the webpage you are trying to parse? I need the link to show you how to do it. Commented Oct 20, 2011 at 19:29
  • or the css tag or attribute..like div class or div id. Commented Oct 20, 2011 at 19:30

1 Answer 1

1

You just need to create an own WebViewClient. Then you can save the url before it get called/shown:

private class MyWebViewClient extends WebViewClient {
    @Override
    public boolean shouldOverrideUrlLoading(WebView view, String url) {

                    // save url here

        // false = open all urls with the embedded browser 
        return false;
    }
}

now add your Webview client to the webview:

    webView.setWebViewClient(new MyWebViewClient());
Sign up to request clarification or add additional context in comments.

3 Comments

sry i think i didnt explain correctly. i already have my webviewclient that load the webpage that include the url as html link
My code should be called everytime a link inside your webview is clicked. Isn't that what you want? Isn't the link as a normal <a href element in the website? If so, you could try a regular expression on the content...
i dont want to click the link, i just want to parse when webpage loads.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.