Subrat
Subrat

Reputation: 3988

Restrict to call a number in a webview in android

I have created a webview . I have loaded the URL by using the loadUrl(). In the webview , some 9 and 10 digits are there. While clicking on the numbers it will give a phone call and calling action is going on. But I want to stop the phone call. Actually these numbers contains hyperlinks. So when I click on number it should redirect to the corresponding url. So what to do to restrict the phone call ?

Upvotes: 2

Views: 448

Answers (1)

Philzen
Philzen

Reputation: 4647

:) One of the top gotchas, took me also quite a while until i realised the behind the scenes-bits...

Touch browsers != desktop browsers is the curriculum, the lessons are in the events.

Actually these numbers contains hyperlinks.

Not quite. The WebView has certain standard behaviour, that get's triggered on a certain events, in this case, it sees a touch just ended on a number that could be a tel.no. - and just dials it. When browsing the "classic" web, that might be a useful feature, here it isn't. So lets start the curriculum:

  1. Load a testpage like this http://www.snappymaria.com/misc/TouchEventTest_v2.html in your WebView. Notice the events happening.

    I'm not sure now which one is the "naughty event" (basically it's the browser doing naughty things when it receives it), but i think you'll need at least "touchend" to stop that "select-and-call"-feature from firing.

  2. In your HTML app, you will need to listen to each of those events like this

    addEventListener( 'touchend', preventDefaultHandler);
    

and then your handler goes s.th.

    function preventDefaultHandler( event ) {
        event.preventDefault();
        return false;
    }

You might wanna try and experiment yourself how the events make the WebView tick (and which one you'll therefore stop by calling preventDefault(). On my HTC Vision with 2.3.3, i was first surprised when i realised the phone also generates "mousemove" events together with touchdown and touchmove... but then disable all those events and try browsing any "normal" webpage designed for desktop, and find that you cannot use it any more.

Upvotes: 2

Related Questions