【问题标题】:config.xml prevent "Open With" dialog androidconfig.xml 阻止“打开方式”对话框android
【发布时间】:2017-01-20 04:56:47
【问题描述】:

我写了一个 phonegap 应用程序,我在 Android 上遇到的问题是当我点击任何链接时,它会转到应用程序中的链接,但它也会打开“打开方式”对话框。这是一个烦恼。怎么可能关掉?我尝试更改我的 config.xml 文件标签,但仍然没有成功?

我试过了

<allow-intent href="http://*/*" />
<allow-intent href="https://*/*" />
<allow-intent href="tel:*" />
<allow-intent href="sms:*" />
<allow-intent href="mailto:*" />
<allow-intent href="geo:*" />
<allow-navigation href="*" />

但得到以下对话框:

【问题讨论】:

  • 我很确定您必须编写一些 java 代码来确保应用程序已安装并将意图直接发送给它。我不确定这是否可能仅使用 phonegap html/xml
  • 我找到了另一种方法,但它需要将所有锚标签更改为跨标签。无论如何,我使用 jQuery 类来触发我的所有事件,但之前必须有人遇到过这种情况

标签: android xml cordova


【解决方案1】:

对于遇到这种情况的人。如果您使用哈希 href 并使用类在 jQuery 中触发事件,则可以修复它。我只是删除了应用程序中所有锚标记的 href 属性,这解决了问题。

<a href="#" class="btn">

if(android){
    $("a").each(function(){
        if($(this).attr("href") == "#"){
            $(this).removeAttr("href");
        }
    });
}

变成这样:

<a class="btn">

如果我们有一个像 #collapsable_id 这样的 id 的 href

if(android){
    $(document).on(evt, 'a', function(e) {
        if($(this).attr("href") != undefined && $(this).attr("href") != "#"){
            e.stopImmediatePropagation();
        }
    });
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-08-31
    • 1970-01-01
    • 2016-04-10
    • 2019-06-21
    • 2011-10-18
    • 1970-01-01
    相关资源
    最近更新 更多