javascript PhoneGap - 打开外部应用程序
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/22168015/
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
PhoneGap - Open external application
提问by amd
I am developing a PhoneGap App, All what I need is to open an external application.
我正在开发一个 PhoneGap 应用程序,我只需要打开一个外部应用程序。
e.g. my app namespace is com.demo.app1and I need to open the com.demo.app2application, Is this feasible ?
例如,我的应用程序命名空间是com.demo.app1,我需要打开com.demo.app2应用程序,这可行吗?
- I am using PhoneGap 3.3
- I found that there is many versions of the WebIntent plugin
- An example may help :)
- 我正在使用 PhoneGap 3.3
- 我发现WebIntent插件有很多版本
- 一个例子可能会有所帮助:)
Thanks
谢谢
采纳答案by amd
Finally, I implemented my own plugin that offer the following:
最后,我实现了自己的插件,提供以下功能:
- getUniqueDeviceId (return a unique device ID)
- openApp (open an installed app, and fallback to the store if available)
- openStore (open the store on a specific app)
- getUniqueDeviceId(返回唯一的设备 ID)
- openApp(打开已安装的应用程序,如果可用,则回退到商店)
- openStore(在特定应用上打开商店)
http://ahmad-moussawi.github.io/pgutils/
http://ahmad-moussawi.github.io/pgutils/
Please feel free to contribute or suggest any other feature.
请随时贡献或建议任何其他功能。
回答by jcesarmobile
You can crea a plugin with this java code:
你可以用这个java代码创建一个插件:
Intent LaunchIntent = this.cordova.getActivity().getPackageManager().getLaunchIntentForPackage("com.demo.app2");
this.cordova.getActivity().startActivity(LaunchIntent);
or try any of this 2 plugins for launching apps
或尝试这 2 个插件中的任何一个来启动应用程序
https://github.com/lampaa/org.apache.cordova.startapp
https://github.com/lampaa/org.apache.cordova.startapp
回答by QuickFix
Finally found my old code of when I was using webintent :
终于找到了我使用 webintent 时的旧代码:
CDV.WEBINTENT.launchActivity("com.demo.app1",
function() {
console.log("Activity started");
},
function() {
console.log("Error starting activity");
}
);
There are two different gits for webintent referenced in phonegap build for phonegap 3.x, no idea what the differences are (and the first one is the one I was using) :
在 phonegap 3.x 的 phonegap build 中引用了两个不同的 webintent git,不知道有什么区别(第一个是我使用的那个):
- https://github.com/InQBarna/WebIntent.git
- https://github.com/Tunts/WebIntent/
- https://github.com/acen99/WebIntent/
- https://github.com/InQBarna/WebIntent.git
- https://github.com/Tunts/WebIntent/
- https://github.com/acen99/WebIntent/
And an other usefull plugin is the webavailability plugin that lets you know if the other app is installed before you try to launch it : https://github.com/ohh2ahh/AppAvailability.git
另一个有用的插件是 webavailability 插件,它可以让您在尝试启动之前知道其他应用程序是否已安装:https: //github.com/ohh2ahh/AppAvailability.git
I stopped using webintent because I needed to be able to switch to an app if it was already started and not relanch it.
我停止使用 webintent,因为我需要能够切换到已经启动的应用程序而不是重新启动它。
EDIT: oops again, launchactivity was a function I added to the plugin... will check later how I was doing before this.
编辑:再次糟糕,launchactivity 是我添加到插件中的一个功能......稍后将检查我在此之前的表现。
回答by Vanger
In iOS to open any application you need to know which URLs schemes supported by this app.
在 iOS 中打开任何应用程序,您需要知道此应用程序支持哪些 URL 方案。
For example, you can open email-writer by url like "mailto:[email protected]". But the thing is in application you can declare your own scheme. For example in App1 you can declare schemelike "my-app1-scheme". And in your second app you will need to open URL "my-app1-scheme://" and your App1 will be opened.
例如,您可以通过像“mailto:[email protected]”这样的 url 打开 email-writer。但问题是在应用程序中,您可以声明自己的方案。例如在 App1 中,您可以声明像“my-app1-scheme”这样的方案。在您的第二个应用程序中,您需要打开 URL“my-app1-scheme://”,然后您的 App1 将被打开。
And I just found this plugin that allows you to do this in simpler way: https://github.com/EddyVerbruggen/LaunchMyApp-PhoneGap-Plugin
我刚刚发现这个插件可以让你以更简单的方式做到这一点:https: //github.com/EddyVerbruggen/LaunchMyApp-PhoneGap-Plugin