升级到cordova 3.6.3后,“tel”、“sms”和“mailto”在Android中不再有效

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/26271313/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 11:11:38  来源:igfitidea点击:

“tel”, “sms”, and “mailto” no longer working in Android after upgrading to cordova 3.6.3

androidcordova

提问by abelabbesnabi

I recently upgraded my cordova based Android app from 3.5.0 to 3.6.3. The special links "tel", "sms", and "mailto" stopped working. When clicked, nothing happens. Is there anything I can do in the AndroidManifest.xml, or Confix.xml or anything else to get them back working?

我最近将基于cordova 的Android 应用程序从3.5.0 升级到3.6.3。特殊链接“tel”、“sms”和“mailto”停止工作。单击时,没有任何反应。我可以在 AndroidManifest.xml 或 Confix.xml 或其他任何东西中做些什么来让它们恢复工作?

I built two identical and very simple android apps to prove my suspicion, one with cordova 3.5.0 and one with 3.6.3. Both of them have a simple link:

我构建了两个相同且非常简单的 android 应用程序来证明我的怀疑,一个使用cordova 3.5.0,一个使用3.6.3。他们都有一个简单的链接:

<a href="tel:1(858)xxx-xxxx">Call</a>

The first one works, the second one doesn't work.

第一个有效,第二个无效。

I think they added a security feature that blocks intents somehow.

我认为他们添加了一项以某种方式阻止意图的安全功能。

PS: both apps built like this:

PS:这两个应用程序都是这样构建的:

cordova create app com.tmp.app "App"
cordova platform add android

and in index.html, I added the telephone link above on the device ready block.

在 index.html 中,我在设备就绪块上添加了上面的电话链接。

Please help.

请帮忙。

回答by abelabbesnabi

I finally found the answer. All you have to do is add the following to config.xml:

我终于找到了答案。您所要做的就是将以下内容添加到 config.xml 中:

<access origin="tel:*" launch-external="yes"/>
<access origin="geo:*" launch-external="yes"/>
<access origin="mailto:*" launch-external="yes"/>
<access origin="sms:*" launch-external="yes"/>
<access origin="market:*" launch-external="yes"/>

I hope this helps everyone.

我希望这对大家有帮助。

It all started by IBM!!!

一切由IBM开始!!!

IBM Cordova Security Issues

IBM Cordova 安全问题

回答by AAhad

I had an App built on 3.5.1 version and all special links were working fine. But when i upgraded on the latest version 3.6.3 then they did not work.

我有一个建立在 3.5.1 版本上的应用程序,所有特殊链接都工作正常。但是当我升级到最新版本 3.6.3 时,它们不起作用。

So I made below changes in the code and now they works fine.

所以我在代码中进行了以下更改,现在它们工作正常。

  1. Add InAppBrowser plugin

    cordova plugin add org.apache.cordova.inappbrowser

  2. Create custom function in your JS file to open special links within the InApp browser

    var app = {
            initialize: function() {
            this.bindEvents();
        },         
        bindEvents: function() {
            document.addEventListener('deviceready', this.onDeviceReady, false);
        },         
        onDeviceReady: function() {
            app.receivedEvent('deviceready');
        },
        openNativeAppWindow: function(data) {
            window.open(data, '_system');
        }
    

    };

  3. The place where you are invoking special links like sms or tel then pass on your custom url with data and let it open the native browser window which in turn will push the native App to handle the special urls.

  1. 添加 InAppBrowser 插件

    cordova 插件添加 org.apache.cordova.inappbrowser

  2. 在您的 JS 文件中创建自定义函数以在 InApp 浏览器中打开特殊链接

    var app = {
            initialize: function() {
            this.bindEvents();
        },         
        bindEvents: function() {
            document.addEventListener('deviceready', this.onDeviceReady, false);
        },         
        onDeviceReady: function() {
            app.receivedEvent('deviceready');
        },
        openNativeAppWindow: function(data) {
            window.open(data, '_system');
        }
    

    };

  3. 您调用特殊链接(如 sms 或 tel)的地方然后传递带有数据的自定义 url 并让它打开本机浏览器窗口,这反过来将推动本机应用程序处理特殊 url。

Few example:

几个例子:

<br><br><input type="button" onClick="app.openNativeAppWindow('http://google.com')" value="Open Google"/>
            <br><br><a onClick="app.openNativeAppWindow('geo://0,0?q=dallas')" data-rel="external">google maps</a>
            <br><br><a onClick="app.openNativeAppWindow('geo:0,0?q=Bacau')">Geolocation Test</a>
            <br><br><a onClick="app.openNativeAppWindow('geo:0,0?q=34.99,-106.61(Treasure)')">longitude & latitude with a string label</a>
            <br><br><a onClick="app.openNativeAppWindow('geo:0,0?q=1600+Amphitheatre+Parkway%2C+CA')">street address Test</a>
            <br><br><a onClick="app.openNativeAppWindow('sms:2125551212')">SMS</a>
            <br><br><a onClick="app.openNativeAppWindow('mms:2125551212')">MMS</a>
            <br><br><a onClick="app.openNativeAppWindow('tel:2125551212')">Open Phone Dialer</a>

回答by almo

As of Cordova 4.0 you must include the whitelist plugin.

从 Cordova 4.0 开始,您必须包含白名单插件。

<gap:plugin name="cordova-plugin-whitelist" source="npm" />
<allow-intent href="tel:*" />

https://github.com/apache/cordova-plugin-whitelist

https://github.com/apache/cordova-plugin-whitelist

回答by Mohammed Akdim

Modify the Cordova whitelist

修改 Cordova 白名单

One of the security fixes involves creating a new whitelist for non http/sprotocols. If your application uses other protocols besides http://and https://, such as sms:, mailto:, geo:,tel:etc., then you will need to make some configuration changes to add these protocols to the whitelist.

安全修复之一涉及为非http/s协议创建新的白名单。如果应用程序使用之外的其他协议http://https://,如sms:mailto:geo:tel:等,那么你就需要做一些配置更改这些协议添加到白名单中。

This is easy to do:

这很容易做到:

  1. Open up the Cordova config.xml file, located at: yourProject --> apps --> yourProject --> android --> native --> res --> xml --> config.xml. Note: If you have a file located at yourProject --> apps --> yourProject --> android --> nativeResources --> res --> xml, you will have to make the changes to this file (under the nativeResources folder) instead, since if this file exists, it will overwrite the config.xml in /native/ folder when the app is rebuilt.
  2. Scroll to your whitelist entries. You should see items listed like this:

    <access origin="https://my.company.com/resources" />
    <access origin="http://*.othersupplier.com" />
    
  3. For every non http/https protocol that you use, you will have to add a whitelist entry like this:

    <access origin="sms://*" launch-external="true" />
    <access origin="mailto://*" launch-external="true" />
    
  1. 打开 Cordova config.xml 文件,位于:yourProject --> apps --> yourProject --> android --> native --> res --> xml --> config.xml。注意:如果您有一个文件位于 yourProject --> apps --> yourProject --> android --> nativeResources --> res --> xml,则必须对此文件进行更改(在 nativeResources 文件夹下) ) 相反,如果此文件存在,它将在重新构建应用程序时覆盖 /native/ 文件夹中的 config.xml。
  2. 滚动到您的白名单条目。您应该会看到如下所列的项目:

    <access origin="https://my.company.com/resources" />
    <access origin="http://*.othersupplier.com" />
    
  3. 对于您使用的每个非 http/https 协议,您都必须添加一个如下所示的白名单条目:

    <access origin="sms://*" launch-external="true" />
    <access origin="mailto://*" launch-external="true" />
    

The launch-external attribute will tell Cordova to allow this URL to be handled by other applications in Android system - not by the currently running Cordova/Worklight application.

launch-external 属性将告诉 Cordova 允许此 URL 由 Android 系统中的其他应用程序处理 - 而不是由当前运行的 Cordova/Worklight 应用程序处理。

This will mean that when a user clicks on a <a href="sms:555...">link, Android will let whatever application is registered to sms:handle the request.

这意味着当用户点击一个<a href="sms:555...">链接时,Android 会让任何注册的应用程序来sms:处理请求。

If the only entry that is in your whitelist looks like this:

如果白名单中的唯一条目如下所示:

<access origin="*" />

then your application will allow resource requests to any internet resource, which could open your application to certain kinds of attacks.

那么您的应用程序将允许对任何 Internet 资源的资源请求,这可能会使您的应用程序受到某些类型的攻击。

You should list specific domains in this tag that you want to be able to access.

您应该在此标签中列出您希望能够访问的特定域。

If your whitelist looks like this:

如果您的白名单如下所示:

<access origin="https://www.ibm.com" />
<access origin="https://my-worklight-server.company.com" />

and inside your application you utilize the mailto:protocol to open a user's email client, and the geo:protocol to display a map, then you should modify the whitelist to look like:

在您的应用程序中,您使用该mailto:协议打开用户的电子邮件客户端,并使用该geo:协议显示地图,然后您应该将白名单修改为:

<access origin="https://www.ibm.com" />
<access origin="https://my-worklight-server.company.com" />
<access origin="mailto://*" launch-external="true" />
<access origin="geo://*" launch-external="true" />

HTML :

HTML :

<a href="tel:+212x-xx-xx-xx-xx">Call</a>

<a href="tel:+212x-xx-xx-xx-xx">Call</a>

Add to file "config.xml" :

添加到文件“config.xml”:

<access origin="tel:*" launch-external="yes"/>

source :

来源 :

https://www.ibm.com/developerworks/community/blogs/worklight/entry/action_required_cordova_android_security_update?lang=en`

https://www.ibm.com/developerworks/community/blogs/worklight/entry/action_required_cordova_android_security_update?lang=en`