在设备上的默认浏览器打开链接。人行横道Android应用 [英] Open link in device's default browser. Crosswalk android application

查看:328
本文介绍了在设备上的默认浏览器打开链接。人行横道Android应用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了使用HTML和JavaScript Android设备的应用程序。我使用的人行横道(15.44.384.12)捆绑成一个Android应用程序,其中pretty多创造与内置的网页浏览器的Andr​​oid应用程序这一点,运行我的应用程序。

I am creating an app for Android devices using HTML and JavaScript. I am using Crosswalk (15.44.384.12) to bundle this into an Android application, which pretty much creates an android app with a web browser built in, to run my application.

我把一切都在Android设备上工作,但我在努力找出如何使用JavaScript在设备的默认浏览器中打开,从我的应用程序的链接。

I have everything working on the Android device, but I am struggling to find out how to open a link from my app in the device's default browser using JavaScript.

如果我用window.open(),它只是我的应用程序内加载,这不是我想要的。

If I use window.open(), it will just load within my app, which is not what I want.

我一直在使用window.open试过( http://example.com ','_blank'),我还试图'_system,都无济于事。

I have tried using window.open('http://example.com', '_blank'), I have also tried '_system', to no avail.

推荐答案

我也一样。所有的HREF和window.open调用在网页视图中打开。

Same here. All hrefs and window.open calls are opened in the WebView.

我们可以用一种变通方法,这是也有可能在科尔多瓦:拦截在本地Java code网址

We can use a workaround that was also possible in Cordova: to intercept URLs in native Java code.

首先创建一个自定义XWalkResourceClient拦截你的URL根据您的需要:

First create a custom XWalkResourceClient to intercept your urls depending on your needs:

XWalkResourceClient myResourceClient = new XWalkResourceClient(xWalkWebView){
    ...

    @Override
    public boolean shouldOverrideUrlLoading(XWalkView view, String url) {
            if(url.contains("whatever")){
                Intent i = new Intent(Intent.ACTION_VIEW);
                i.setData(Uri.parse(url));
                startActivity(i);

                return true;
            }

            return super.shouldOverrideUrlLoading(view, url);
    }
};

,然后在您的活动,您可以在客户端设置为XWalk观点:

and then in your activity, you can set that client to the XWalk view:

myXWalkWebView.setResourceClient(myResourceClient);

这篇关于在设备上的默认浏览器打开链接。人行横道Android应用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆