简体   繁体   中英

Android webview Override link

I am trying to override the signout link in an android website to redirect to the Intro Activity instead than to the signout page of the website.

private class MyWebViewClient extends WebViewClient {
    @Override
    public boolean shouldOverrideUrlLoading(WebView view, String url) {
        //opens links in webview
        view.loadUrl(url);

        if(url.endsWith("logout")) {
            Intent intent = new Intent(SignIn.this, Menu.class);
            startActivity(intent);
        }
        return true;
    }

NOTE: Of course Menu.class is my first activity (where I want to redirect) and SignIn.this is the current activity where the webview is.

I have being trying several ways, this is what I have now. Any suggestions?

Thanks in advance for your consideration

You can call a javascript method in the click of button "logout"

ex:

<script type="text/javascript">
    function showAndroidLogout() {
        Android.showAndroidLogout();
    }
</script>`

in the Android Activity Signin you can add a JavascriptInterface that contains the implematation of you method

ex: `public class WebAppInterface { Context mContext;

/** Instantiate the interface and set the context */
WebAppInterface(Context c) {
    mContext = c;
}

/** Show Menu activity from the web page */
@JavascriptInterface
public void showLogout() {
     Intent intent = new Intent(SignIn.this, Menu.class);
        startActivity(intent);
}

}`

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM