0

How can I acces webview content on my Android? I have read this post : answer1 but it suggested to use embeded javascript which cause me @SuppressLint("JavascriptInterface") warning so I have decided not to use this method. Can I anyhow acces the content of the body via WebViewClient() ? I also get the content via Json in body but I can not acces any entity to read it.

.setWebViewClient(new WebViewClient(){

            @Override
            public void onPageFinished(WebView view, String url) {

            }

            @Override
            public void onLoadResource(WebView view, String url) {
                if(url.equalsIgnoreCase(the_url)){                  
                    //here get the content
                }
                super.onLoadResource(view, url);
            }
        });

I want achieve something similar to

final HttpEntity httpEntity = httpResponse.getEntity();
            is = httpEntity.getContent(); 

or just simply read the whole String between <body>...</body>

the explanation: I want to log in the user on my website, for security reason I need to load url with the formular, when the user is loged in as response I get both Json with some security token and it is echoed so it looks like this:<body>{"token":"abcd"}</body> But I need that token, and I need that on every device, so I have to find a way how can I read it from JSON or from the webpage. please help me with that.

thanks

Community
  • 1
  • 1
Csabi
  • 3,097
  • 17
  • 59
  • 107
  • 1
    don't get to you extra problem, JavaScriptInterface normally working. See this links: 1. http://stackoverflow.com/questions/9966760/how-i-get-page-source-from-webview , 2. http://stackoverflow.com/questions/2376471/how-do-i-get-the-web-page-contents-from-a-webview – SBotirov May 31 '13 at 09:21
  • I just do not believe that the web view cant tell me what content is in it. Thats fail – Csabi May 31 '13 at 09:38

1 Answers1

2

How can I acces webview content on my Android?

Use the techniques outlined in the answer, using addJavascriptInterface() to register a callback, then using loadUrl() to execute a javascript: URL that retrieves the portion of the DOM that you want and passes it to some method on your callback.

it suggested to use embeded javascript which cause me @SuppressLint("JavascriptInterface") warning

Correct, because if you are loading arbitrary content, that content could try calling your callback when you do not expect it.

so I have decided not to use this method

Then you cannot "acces webview content".

Can I anyhow acces the content of the body via WebViewClient() ?

No.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491