0

I've a problem im my actual android workingset which I don't know to handle it. I hope I'll get help here ;)

I want to fetch contents from a website (which is mine). I have to parse a single html-tag, which works perfectly fine with following source:

WebView webview = new WebView(getApplicationContext());
webview.getSettings().setJavaScriptEnabled(true);
webview.addJavascriptInterface(new JIFace(), "HTMLOUT");
webview.setWebViewClient(new BasicWebViewClient());
webview.loadUrl("http://webaldo.at/blabla.php");

My Webviewclient looks like this:

private class BasicWebViewClient extends WebViewClient {
    @Override
    public boolean shouldOverrideUrlLoading(WebView view, String url) {
        view.loadUrl(url);
        return true;
    }

    @Override
    public void onReceivedError(WebView view, int errorCode,
            String description, String failingUrl) {
        progressRingDialog.dismiss();
        doErrorDialog("Webservice Offline", "Der Webserver kann nicht erreicht werden. Bitte versuche es später nochmal.");

    }

    @Override
    public void onPageFinished(WebView view, String url) {
        super.onPageFinished(view, url);
        if( progressRingDialog != null ) {
            progressRingDialog.dismiss();
        }
        if( alertDialog != null ) {
            alertDialog.dismiss();
        }
        progressRingDialog = ProgressDialog.show(Login.this, getString(R.string.progress_title), "Passwort wird überprüft", true);
        TextView textView = (TextView)findViewById(R.id.statuslabel);
        textView.setText("Benutzername wird geprüft");
        webview.setWebViewClient(new ExtendedWebViewClient());
        webview.loadUrl("javascript:window.HTMLOUT.showHTML(document.getElementsByTagName('x')[0].innerHTML);");
    }

    @Override
    public void onPageStarted(WebView view, String url, Bitmap favicon) {
        super.onPageStarted(view, url, favicon);
    }
}

yes, my tag, I want to parse is

<x></x>

Now, my problem is, that I have to do not a

webview.loadUrl()

because I have to send POST params to the page using this method:

webview.postUrl("http://webaldo.at/blabla.php", EncodingUtils.getBytes("username="+username+"&password="+password, "BASE64"));

In this case, I'll get no data in my JSInterface.

Does anyone of you have similar problems, or knows a better or simplier way to handle my Username/Password autentication problem?

I'm looking forward to good answers.

Kind regards

BTW: the URL doesn't exist in this way, but that shouldn't matter. REST Services aren't supported on my webserver, therefore I have to fix it this way.

JavaDM
  • 851
  • 1
  • 6
  • 29

1 Answers1

0

You could use Jsoup to connect to your site and parse the data and then use the method of the webview to send the data.

Here is an example how you can connect with Jsoup to a specific page:

Document doc = Jsoup.connect("http://en.wikipedia.org/").get();
Elements newsHeadlines = doc.select("#mp-itn b a");

Hope this helps.

Aksiom
  • 1,565
  • 4
  • 25
  • 39
  • And how i can combine this with a webview. Do you have an example for matching those? – JavaDM Apr 22 '14 at 09:05
  • Why do you need to combine it? Maybe I am confused a little here. My Idea was to parse the username and password from your website using Jsoup and then use the webview.postUrl(). – Aksiom Apr 22 '14 at 13:50
  • I get the data from the website only if i send username and password via POST. Username and Password are stored in my app – JavaDM Apr 22 '14 at 16:21