Need to call an activity back from javascript interface made for WebView

后端 未结 2 1090
Happy的楠姐
Happy的楠姐 2020-12-09 14:22

I am working on an application which uses web view in one of it\'s activities. I have attached a java script interface with the web content. I need to call an activity with

2条回答
  •  醉梦人生
    2020-12-09 14:46

    You can use the WebView OnClick to check which link was clicked and take action accordingly. Like this:

    wv.setOnClickListener(new OnClickListener() {
    public boolean onClick(View v){
        HitTestResult result = wv.getHitTestResult();
        String url = result.getExtra();
        //Log.i(myTag, url);
        if(url.equals("which-ever-url-you-want-to-override.com"){
            Intent i = new Intent(getApplicationContext(), yourActivity.class);
            startActivity(i);
        }
    
    
    }
    });
    

    getHitTestResult() will give you an object that will tell you where the URL of the link points. You can use this to make different links do different things within your app.

提交回复
热议问题