1

I am playing an HTML 5 Video inside WebView. That video is containing by 5 slides and one slide will finish then only user can go to next slide and for that he has to press in the next button. But in the last Slide when user will click on the screen then i want to start a new activity. So my concern is how i will find out which is the last slide or when user clicked on that link(Slide).Or can i open new link inside that webview only because wen i clicking on that link again asking me for new session.

I have gone through this link but did not helped me :

Detect click on HTML button through javascript in Android WebView

Community
  • 1
  • 1
user3154663
  • 291
  • 1
  • 2
  • 18

1 Answers1

1

You can add a JSInterface when you load the webview in your activity

    private WebView wb;

    @SuppressLint("SetJavaScriptEnabled")
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_home);
        wb = (WebView) findViewById(R.id.home_webview);
        WebSettings webSettings = wb.getSettings();
        webSettings.setJavaScriptEnabled(true); 
        //Add a JavaScriptInterface, so I can make callbacks from the webView
        wb.addJavascriptInterface(new myJavaScriptInterface(), "CallToAnAndroidFunction");
        wb.loadUrl("http://mywebsite");
    }

     public class myJavaScriptInterface {
         //Add JavascriptInterface annotation for SDK 17
         @JavascriptInterface
         public void myFunction(){
                //startActivity
         }
     }

In your webview you will make a call like this.

For example:

onclick="window.CallToAnAndroidFunction.myFunction()"

AlexBcn
  • 2,450
  • 2
  • 17
  • 28
  • can you tell me how to get exit from the activity when user clicks on Submit button inside the Webview. Anyway thanks for kind support. – user3154663 Jan 23 '14 at 10:42
  • In the activity: Add a newFunction to the JSInterface and execute `finish()`. In the Webview: Add the attribute onSubmit="window.CallToAnAndroidFunction.newFunction()".(onSubmit or after validating your form or whatever you do when you click the button) – AlexBcn Jan 23 '14 at 12:46