Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/208.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 加载XWalkView内的所有链接或打开一个_Android_Crosswalk Runtime - Fatal编程技术网

Android 加载XWalkView内的所有链接或打开一个

Android 加载XWalkView内的所有链接或打开一个,android,crosswalk-runtime,Android,Crosswalk Runtime,我正在使用XWalkView加载页面 我想知道是否有可能拦截页面中链接的加载请求,并将其加载到新的意图弹出窗口或停止加载链接 public WebResourceResponse shouldInterceptLoadRequest(XWalkView view, String url) { Log.d("shouldInterceptLoadRequ","

我正在使用XWalkView加载页面

我想知道是否有可能拦截页面中链接的加载请求,并将其加载到新的意图弹出窗口或停止加载链接

    public WebResourceResponse shouldInterceptLoadRequest(XWalkView view,
                                                          String url) {
        Log.d("shouldInterceptLoadRequ","shouldInterceptLoadRequest " + url);
        return super.shouldInterceptLoadRequest(view, url);
    }
当页面具有链接时,不会调用此函数。 当一个页面有链接时,我得到一个android默认弹出窗口,要求浏览器打开链接

    public WebResourceResponse shouldInterceptLoadRequest(XWalkView view,
                                                          String url) {
        Log.d("shouldInterceptLoadRequ","shouldInterceptLoadRequest " + url);
        return super.shouldInterceptLoadRequest(view, url);
    }
如果url是google maps location,我需要打开google maps应用程序

我确实尝试过默认的android WebView,但是html5的支持太弱了

编辑

我应该使用

public boolean shouldOverrideUrlLoading(XWalkView view, String url)
但它看起来有一个外部链接的bug:

编辑2

当链接的target=\u为空时会出现问题

public class MyActivity extends Activity {
private XWalkView xWalkWebView;
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.my_activity_xml);
    xWalkWebView = (XWalkView)findViewById(R.id.xwalkView);
    xWalkWebView.addJavascriptInterface(new WebAppInterface(), "Android");
    xWalkWebView.load(url_your_want_to_load,null);
}

public class WebAppInterface {
    @org.xwalk.core.JavascriptInterface
    public void callFunction(){
        // Do your Android Stuff here
    }
}

现在调用页面中的函数:-Android.callFunction

它固定在beta:14.43.343.1

shouldOverrideUrlLoading和shouldInterceptLoadRequest现在都在工作。

您可以从主Web视图捕获onCreateWindowRequested, 让一个虚拟WebView来处理请求:只需将URL块加载并在系统浏览器中打开即可

XWalkPreferences.setValue(XWalkPreferences.SUPPORT_MULTIPLE_WINDOWS, true);
XWalkPreferences.setValue(XWalkPreferences.JAVASCRIPT_CAN_OPEN_WINDOW, true);

XWalkView popupView = new XWalkView(context);

popupView.setUIClient(new XWalkUIClient(popupView){
    @Override
    public void onPageLoadStarted(XWalkView view, String url) {
        Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
        view.getContext().startActivity(browserIntent);
        view.stopLoading();
    }
});

mainWebView.setUIClient(new XWalkUIClient(this){

    @Override
    public boolean onCreateWindowRequested(XWalkView view, InitiateBy initiator, ValueCallback<XWalkView> callback) {
        callback.onReceiveValue(popupView);
        return true;
    }
});