android - Cordova : Open a link using Google Chrome

标签 android cordova google-chrome

我想使用 Google Chrome(不是其他浏览器)从我的 Cordova 应用程序打开一个链接。我尝试了几种解决方案,但没有任何效果。

首先,我尝试创建一个指向 googlechrome:// 的链接(使用 HTML <a> 标签)。它会打开 Google Chrome,但我无法选择要打开的 URL。

然后,我尝试创建一个指向 intent://my.url.com/#Intent;scheme=https;package=com.android.chrome;end 的链接.当我从浏览器(如 Firefox 或 Google Chrome)打开它时,此链接有效,但当我从我的 Cordova 应用程序打开它时,它不起作用。

我还尝试使用 cordova-webintent插件,就像那样:

window.plugins.webintent.startActivity(
    {
        action: window.plugins.webintent.ACTION_VIEW,
        url: 'intent://my.url.com/#Intent;scheme=https;package=com.android.chrome;end'
    },
    function() {
        alert(url);
    },
    function(){
        alert('Failed to open URL via Android Intent');
    }
);

但是我得到一个“无法通过 Android Intent 打开 URL” 错误。

我该怎么办?

PS:我写了<allow-intent href="*" />在我的 config.xml 文件中。

最佳答案

您可以使用 cordova-plugin-inappbrowser_system 为目标:

cordova.InAppBrowser.open('http://stackoverflow.com', '_system', 'location=yes');

或者您可以使用 cordova-plugin-webintent2 (不知道你用的是不是这个),像这样:

window.plugins.webintent.startActivity({
        action: window.plugins.webintent.ACTION_VIEW,
        url:  "googlechrome://navigate?url=http://www.stackoverflow.com"
    },
    function() {},
    function() {
        alert('Failed to open URL via Android Intent.');
      console.log("Failed to open URL via Android Intent.")
    });

url必须以http或https开头,不允许相对url。

关于android - Cordova : Open a link using Google Chrome,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38094005/

相关文章:

javascript - 无法使用 JavaScript 打开 chrome 浏览器

google-chrome - CSS3 过渡留下了痕迹

android - 字符串 webview 中的 html 标签 <div>

javascript - 在 phonegap 中的 2 个 html 页面之间导航

ios - 使用 PhoneGap 3.2 在 iOS 7 上延迟后淡入启动画面

android - 在移动应用程序上播放受 vimeo 域限制的视频

google-chrome - 为网页上的 Chrome 扩展添加右键单击选项

android - 当新的 USB 连接/分离时,通过 wifi 的 adb 连接被终止

java - 在另一个 Activity 中显示选定的图像

android - 关于本地/远程服务、广播接收器和 Intent 服务的结构问题