Android WebView Protocol Handler

3.4k Views Asked by At

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.

1

There are 1 best solutions below

1
On

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.