2014-10-09 58 views
32

我最近將基於cordova的Android應用程序從3.5.0升級到3.6.3。特殊鏈接「tel」,「sms」和「mailto」停止工作。點擊時,沒有任何反應。有什麼我可以在AndroidManifest.xml或Confix.xml或其他任何可以使它們恢復工作的地方?升級到科爾多瓦後,「tel」,「sms」和「mailto」不能在Android上工作3.6.3

我建立了兩個相同和非常簡單的android應用程序來證明我的懷疑,一個是cordova 3.5.0,一個是3.6.3。他們都有一個簡單的鏈接:

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

第一個工作,第二個不工作。

我認爲他們增加了一個安全功能,以某種方式阻止意圖。

PS:這兩個應用建立這樣的:

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

和index.html中,我添加上述設備準備塊上的電話鏈路。

請幫忙。

回答

8

我有一個應用程序建立在3.5.1版本和所有特殊鏈接工作罰款。但是,當我升級最新版本3.6.3,然後他們沒有工作。

所以我在代碼中進行了下面的改變,現在它們工作正常。

  1. 添加InAppBrowser插件

    科爾多瓦插件添加org.apache.cordova.inappbrowser

  2. 在你的JS文件,打開應用程式內瀏覽器中的特殊鏈接創建自定義功能

    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. 你在哪裏上的數據自定義URL調用類似短信或電話的特殊鏈接,然後 通,讓它打開本地瀏覽器 窗口,它反過來將推動原生應用程序來處理的特殊 網址的地方。

幾個例子:

<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> 
+0

我會試試看AAhad。非常感謝你。只有一個問題:它會打開InAppBrowser然後重定向,還是直接進入電話或電子郵件應用程序?因爲屏幕上的中間階段(通過InAppBrowser)並不是一個好的體驗。再次感謝。 – abelabbesnabi 2014-10-09 15:49:54

89

我終於找到了答案。所有你需要做的是將以下內容添加到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"/> 

我希望這可以幫助每個人。

這一切都由IBM開始!

IBM Cordova Security Issues

+8

在我刪除之前,這並不適用於我:。 – 2015-04-29 01:00:49

+2

這個'launch-external'目前沒有記錄在白名單插件中,但根據代碼它和''標籤一樣 – 2015-07-24 10:29:23

+1

而不是簡單的鏈接,window.open('geo:xxxxx,xxxxxx',' _system')在刪除後爲我工作 – Michael 2015-12-01 20:27:21

3

修改科爾多瓦白名單

其中一個安全補丁涉及創建非http/s協議新的白名單。如果您的應用程序使用除http://https://之外的其他協議,例如sms:mailto:geo:,tel:等,則您需要進行一些配置更改以將這些協議添加到白名單。

這是很容易做到:

  1. 開拓科爾多瓦config.xml文件,位於:yourProject - >應用程序 - > yourProject - > Android的 - >本地 - >水庫 - - > xml - > config.xml。注意:如果您的文件位於您的項目 - >應用程序 - > 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" /> 
    

推出-external屬性將告訴Cordova允許此URL由Android系統中的其他應用程序處理 - 而不是由當前運行的Cordova/Worklight應用程序處理。

這意味着當用戶點擊<a href="sms:555...">鏈接時,Android會讓任何註冊到sms:的應用程序處理請求。

如果是在白名單中的唯一入口是這樣的:

<access origin="*" /> 

那麼你的應用程序將允許任何互聯網資源,這可能會打開你的應用程序對某些類型的攻擊資源請求。

您應該列出您希望能夠訪問的標籤中的特定域。

如果你的白名單看起來是這樣的:

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

和你的應用程序中,你利用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:

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

加入檔案「config。XML」:

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

來源:

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

+0

'mailto'和'tel'幫助我!然而,我仍然無法弄清楚如何讓短信爲iOS工作。任何線索? – Shotbyabel 2016-07-21 22:15:00

相關問題