Search in sources :

Example 1 with HtmlToAndroidInstructionsInterface

use of com.telenor.connect.sms.HtmlToAndroidInstructionsInterface in project connect-android-sdk by telenordigital.

the class WebViewHelper method setupWebView.

// 1. HtmlToAndroidInstructionsInterface has no public fields.
// 2. We need JS for the web page.
@SuppressLint({ "AddJavascriptInterface", "SetJavaScriptEnabled" })
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public static void setupWebView(final WebView webView, ConnectWebViewClient client, final String pageToLoad) {
    webView.setWebViewClient(client);
    webView.setVerticalScrollBarEnabled(true);
    webView.setHorizontalScrollBarEnabled(false);
    final WebSettings settings = webView.getSettings();
    settings.setJavaScriptEnabled(true);
    settings.setSaveFormData(false);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        settings.setMixedContentMode(WebSettings.MIXED_CONTENT_COMPATIBILITY_MODE);
    }
    webView.addJavascriptInterface(new HtmlToAndroidInstructionsInterface(client), "AndroidInterface");
    webView.setFocusable(true);
    webView.setFocusableInTouchMode(true);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        WebView.setWebContentsDebuggingEnabled(true);
    }
    acceptAllCookies(webView);
    webView.loadUrl(pageToLoad);
    webView.postDelayed(new RepeatingDelayedPageReloader(webView, pageToLoad), WEB_VIEW_TIMEOUT);
}
Also used : WebSettings(android.webkit.WebSettings) HtmlToAndroidInstructionsInterface(com.telenor.connect.sms.HtmlToAndroidInstructionsInterface) SuppressLint(android.annotation.SuppressLint) TargetApi(android.annotation.TargetApi)

Aggregations

SuppressLint (android.annotation.SuppressLint)1 TargetApi (android.annotation.TargetApi)1 WebSettings (android.webkit.WebSettings)1 HtmlToAndroidInstructionsInterface (com.telenor.connect.sms.HtmlToAndroidInstructionsInterface)1