7

I am trying to develop an Android browser application using WebView which enables users to access content from a custom protocol. The custom protocol could be foobar://

I want to intercept all requests to this custom protocol. This means:

  1. GET requests
  2. POST requests

and I need to be able to hand the results of these operations back to the WebView.

The GET requests can be handled using shouldInterceptRequest (available from API level 11).

Now my problem is: How can I incercept and handle POST requests?

Nearly the same question has been asked here and here, however no solutions for their problems have been found.

Community
  • 1
  • 1
foens
  • 8,642
  • 2
  • 36
  • 48

1 Answers1

0

have you tried overriding for the post method doing something like:

private class ViewerWebViewClient extends WebViewClient {

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

        }

        @Override
        public boolean shouldOverrideUrlLoading( WebView view, final String url ) {
            if(!url.contains(MYKEYWORD))
                {
                Toast.makeText(getActivity(),POSTING, Toast.LENGTH_LONG).show();
                return true;
                }
            return super.shouldOverrideUrlLoading(view, url);
        }
    }

its just an idea. that maybe could help you.

Raykud
  • 2,488
  • 3
  • 21
  • 41
  • 2
    This is useful if the user is navigating to some URL and leaves the current page. I can then use WebView.loadUrl(...) or .post(...). If however the browser is just doing a background request (think javascript) then I can't return the content for it. shouldInterceptRequest can handle GET requests and return the content, but it is not possible to intercept POST requests and get the POST data. Unfortunately your method does not solve the issue. Thank you for trying though! – foens Jun 08 '12 at 09:31