XWalkView,onCreateWindowRequested不起作用

时间:2017-09-05 09:17:57

标签: android webview xwalkview

onCreateWindowRequested不能用于我的代码...... 我不知道为什么...... 我搜索谷歌,我尽我所能,但我无法解决这个问题...... 这段代码是写给我的最终代码。

这段代码的问题是什么?拜托,给我解决。 谢谢。

Webview设置代码

NewWalkUIClient walkUIClient = new NewWalkUIClient(mWeb);
    NewXwalkResource walkResource = new NewXwalkResource(mWeb);

    mWeb.setUIClient(walkUIClient);
    mWeb.setResourceClient(walkResource);

    mWeb.getSettings().setLoadWithOverviewMode(true);
    mWeb.getSettings().setUseWideViewPort(true);
    mWeb.getSettings().setJavaScriptEnabled(true);

    mWeb.getSettings().setDomStorageEnabled(true);
    mWeb.getSettings().setSupportZoom(false);
    mWeb.getSettings().setBuiltInZoomControls(false);

    mWeb.clearCache(true);
    mWeb.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);

    mWeb.getSettings().setSaveFormData(false);
    mWeb.clearFormData();

    mWeb.getSettings().setSupportMultipleWindows(true);
    mWeb.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);

NewWalkUIClient

public class NewWalkUIClient extends XWalkUIClient {

    public NewWalkUIClient(XWalkView view) {
        super(view);
    }

    @Override
    public void onPageLoadStopped(XWalkView view, String url, LoadStatus status) {
        super.onPageLoadStopped(view, url, status);

        if(mWeb != null) {
            mWeb.getNavigationHistory().clear();
            mWeb.clearCache(true);
        }
    }

    @Override
    public void onJavascriptCloseWindow(XWalkView view) {
        super.onJavascriptCloseWindow(view);


    }

    @Override
    public boolean onCreateWindowRequested(XWalkView view, InitiateBy initiator, ValueCallback<XWalkView> callback) {
        Log.d("TAG", "onCreateWindowRequested: ");
        XWalkView newView = new XWalkView(thisActivity);

        newView.setUIClient(new NewWalkUIClient(newView));
        // other initialization like your initial XWalkView object

        callback.onReceiveValue(newView);
        return true;
    }
}

NewXWalkResource

public class NewXwalkResource extends XWalkResourceClient {

    public NewXwalkResource(XWalkView view) {
        super(view);
    }

    @Override
    public void onLoadStarted(XWalkView view, String url) {
        super.onLoadStarted(view, url);

    }

    @Override
    public void onLoadFinished(XWalkView view, String url) {
        super.onLoadFinished(view, url);


    }

    @Override
    public boolean shouldOverrideUrlLoading(XWalkView view, String url) {
        if (url.startsWith("tel:")) {
            Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
            intent.addCategory(Intent.CATEGORY_BROWSABLE);
            intent.putExtra(Browser.EXTRA_APPLICATION_ID, appContext.getPackageName());
            Intent i = new Intent(Intent.ACTION_DIAL , Uri.parse(url));
            startActivity(i);
        } else {
            // MARK : Load Web URL
            mWeb.load(url, null);
        }
        return true;
    }
  }

0 个答案:

没有答案