Click here to Skip to main content
16,019,619 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
is there any way to detect the clicks in the webview?

I am opening a website in my android app and I want to show ads on the specific number of clicks in the app. So, is there anyway? I can detect whether the user has clicked or not? and based on click I can show ads to them?

What I have tried:

what code should I add to check whether the user has clicked or not in the webview?
I don't know how to detect it because there is no button that i have placed manually all the material is of website
Posted
Updated 8-Jun-18 22:04pm
v2
Comments
David Crow 8-Jun-18 23:03pm    
Have you seen this?
nikhil arora 9-Jun-18 11:47am    
yes buddy but it didn't worked for me :(
i am opening webview in fragment i tried throught stackoverflow's each post.

One method-->https://medium.com/@kpbird/android-webview-detect-html-element-on-click-263431c52e01 worked but it could able to detect only 2clicks :(
when i changed return statement to true in below mentioned code:

wv.setOnTouchListener(new View.OnTouchListener() {

public boolean onTouch(View v, MotionEvent event) {
WebView.HitTestResult hr = ((WebView)v).getHitTestResult();

return false;
}
});

It could able to detect clicks but i wasn't able to scroll down after that

1 solution

You can be notified about clicking on links like so:

webView.setWebViewClient(new WebViewClient() {
  @Override
  public boolean shouldOverrideUrlLoading(WebView view, String url) {
    // The webView is about to navigate to the specified url.	
    return super.shouldOverrideUrlLoading(view, url);
  }
});
 
Share this answer
 
Comments
nikhil arora 9-Jun-18 11:48am    
i don't want to get notified on links i want to get notified on just click
no image no hyperlinks.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900