We can detect the following HTML elements according to the Android API docs.
int ANCHOR_TYPE HitTestResult for hitting a HTML::a tag int EDIT_TEXT_TYPE HitTestResult for hitting an edit text area int EMAIL_TYPE HitTestResult for hitting an email address int GEO_TYPE HitTestResult for hitting a map address int IMAGE_ANCHOR_TYPE HitTestResult for hitting a HTML::a tag which contains HTML::img int IMAGE_TYPE HitTestResult for hitting an HTML::img tag int PHONE_TYPE HitTestResult for hitting a phone number int SRC_ANCHOR_TYPE HitTestResult for hitting a HTML::a tag with src=http int SRC_IMAGE_ANCHOR_TYPE HitTestResult for hitting a HTML::a tag with src=http + HTML::img int UNKNOWN_TYPE Default HitTestResult, where the target is unknown
I think you can get all the events using the WebView function setOnTouchListener.
WebView has an inner class called HitTestResult . The HitTestResult class will help us find the HTML element that clicks when the user clicks on the WebView.
The HitTestResult class has only two methods.
- getExtra (): returns a string. String has an HTML element that the user clicked.
- getType (): returns an integer. It is used to determine which HTML element the user clicked.
You can do this:
wv.setOnTouchListener(new View.OnTouchListener() { public boolean onTouch(View v, MotionEvent event) { WebView.HitTestResult hr = ((WebView)v).getHitTestResult(); Log.i(TAG, "getExtra = "+ hr.getExtra() + "\t\t Type=" + hr.getType()); return false; } });
Edited: See Perfect Answer: Detect click HTML button via javascript in Android WebView
Kartik domadiya
source share