cordova如何从http或https url打开应用程序? [英] how can cordova open app from http or https url?
问题描述
对于这样的自定义URL方案,我发现了很多答案( mycoolapp://somepath
).
插件,修改了android清单文件-将这些行添加到活动中
< intent-filter>< action android:name ="android.intent.action.VIEW"/>< category android:name ="android.intent.category.DEFAULT"/>< category android:name ="android.intent.category.BROWSABLE"/>< data android:host ="example.com" android:scheme ="http"/></intent-filter>
并在设备就绪时修改了index.html:
function deviceReady(){window.plugins.webintent.getUri(function(url){console.log("INTENT URL:" + url);//...});}
编辑
我刚刚注意到一种可能不受欢迎的行为.当您使用另一个应用程序的链接(意图)打开该应用程序时,它将(在许多情况下)创建一个新实例,而不使用已经运行的实例(已通过gmail和skype测试).为避免这种情况,解决方案是在config.xml文件中更改Android启动模式:
< preference name ="AndroidLaunchMode" value ="singleTask"/>
(它适用于cordova 3.5,不确定较旧的版本)
然后,您需要为ondeviceready添加一个功能:
window.plugins.webintent.onNewIntent(function(url){console.log("INTENT onNewIntent:" + url);});
当应用已经运行并被故意带到最前时触发该事件.
I found many answers for a custom URL-Scheme like this (mycoolapp://somepath
).
This plugin for example adds a custom URL-Sheme.*
But I don't want a custom URL-Scheme, I want a "normal" URL like this (http://www.mycoolapp.com/somepath
).
If you open this in you Browser or click on a Hyperlink for example, then it should ask you to open my app (like google maps does it).
This question maybe already has an answer, but i can't find it.
If you don't know what I mean, that's how it should look if you click on the link to my website on an Android Device:
Just with my app to select.
For the same problem I've used existing webintent plugin, modified the android manifest file - add those lines to activity
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:host="example.com" android:scheme="http" />
</intent-filter>
and modified the index.html ondeviceready:
function deviceReady() {
window.plugins.webintent.getUri(function(url) {
console.log("INTENT URL: " + url);
//...
});
}
EDIT
I've just noticed a behavior which may be unwanted. When you open the app using the link (intent) from another application, it will (in many cases) create a new instance and not use the already running one (tested with gmail and skype). To prevent this a solution is to change Android Launch mode in config.xml file:
<preference name="AndroidLaunchMode" value="singleTask" />
(It works with cordova 3.5, not sure about the older version)
Then you need to add one more function to ondeviceready:
window.plugins.webintent.onNewIntent(function(url) {
console.log("INTENT onNewIntent: " + url);
});
This one is triggered when the app was already running and was brought to front with intent.
这篇关于cordova如何从http或https url打开应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!