4

I'm about to develop a browser plugin that detects whether a page is WML and if so, it will be transformed to HTML via an API.

What I want to do is override onPageFinished in WebViewClient and get MIME type from WebView. But there seems no such kind of methods in those two classes.

Am I missing anything or are there some other approaches? Any advice given will be appreciated.

neuront
  • 9,312
  • 5
  • 42
  • 71

2 Answers2

2

You can try using MimeTypeMap's

getFileExtensionFromUrl() followed by getMimeTypeFromExtension()

Reno
  • 33,594
  • 11
  • 89
  • 102
  • 1
    Thanks, but that won't help if the URL just ends up with `php`, `aspx`, etc. I think I should check the DOM to see DOCTYPE is wml or the root of the XML is ``. – neuront Jul 29 '11 at 06:40
  • How about [guessContentTypeFromStream()](http://developer.android.com/reference/java/net/URLConnection.html#guessContentTypeFromStream(java.io.InputStream)) you can use [this](http://stackoverflow.com/questions/3134389/access-the-http-response-headers-in-a-webview/3134609#3134609) to get an InputStream – Reno Jul 29 '11 at 07:06
  • Thanks for the hint, and I have found a new approach. – neuront Jul 29 '11 at 12:27
1

I have just come up with an idea and seems work.

Load a javascript with loadUrl when the page is finish loading (onProgressChange to 100%). The js code is like

javascript:(function() {
    var wml_root = document.getElementsByTagName('wml');
    if (wml_root && wml_root.length > 0) {
        // apply an XLST or do something here...
    }
})()
neuront
  • 9,312
  • 5
  • 42
  • 71