1

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

新XWalk资源

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

0 回答 0