2017-10-02 14 views
1

アンドロイドのウェブサイトのサインアウトリンクをオーバーライドして、ウェブサイトのサインアウトページではなくイントロアクティビティにリダイレクトしようとしています。Android webviewオーバーライドリンク

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; 
    } 

注:もちろんMenu.classは(私はリダイレクトする)私の最初の活動であるとSignIn.thisはWebViewのが現在の活動です。

私はいくつかの方法を試していますが、これは私が今持っているものです。助言がありますか?あなたの検討のため、事前に

ありがとうございますが

EX「ログアウト」ボタンのクリックでjavascriptのメソッドを呼び出すことができます

答えて

0

:Androidのアクティビティのサインインもで

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

あなたが追加することができますあなたの実装を含むJavascriptInterfaceメソッド

例: `public class WebAppInterface { コンテキストmC ontext;

/** 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); 
} 

} `

+0

おかげcroenilsoが、あなたのソリューションがovercomplexです正直に言うと。すでにjavascriptを使用しているWebviewにjavascriptを注入すると、競合のリスクが増加し、完全にネイティブのアプリケーションと比較して、すでに遅いソリューションのすべてが減速します。 私は実際には私のwebclientsetting作業をしようとしています –