AppDeveloper122
AppDeveloper122

Reputation: 143

Detect and append POST parameters in Android WebView

I am developing an app for Android that relies heavily on internet content. In the app I have a WebView that lets the user browse our secure website. This is working great. However some times we need to trigger a method in our native app.

To do this we need to intercept a POST request when the user submits a form, look for a specific parameter, and if the parameter is there, append another parameter to the POST request before submitting it.

It is important that our app supports older APIs. At least API level 8. In iOS this was a piece of cake. We just intercepted the URL reques and appended our url encoded parameter. In Android however it is much harder. I am unable to find a way to intercept the request without making any changes to our website.

I have tried overriding the webviews loadUrl() method and postUrl() method, but it seems they are not called when the user interacts with a href in the webview. The specific parameter we are looking for can come from different urls, so it is not enought to override the url itself or hardcode the form name. I hope someone is able to help me with this problem.

Upvotes: 0

Views: 2457

Answers (2)

greenapps
greenapps

Reputation: 21

You can use javascript to intercept the posting. As you can validate all inputs with javascript you can also set up all key=value pairs. The javascript itself can only execute a get request. If that is not allowed use an android javascript bridge to execute a post.

Upvotes: 2

jithinroy
jithinroy

Reputation: 1885

Check out the WebViewClient http://developer.android.com/reference/android/webkit/WebView.html#setWebViewClient(android.webkit.WebViewClient) for the webview. Using this you can handle all the request going through your webview.

Upvotes: -1

Related Questions