如何从PhoneGap / Cordova应用程序直接导航到Google Play商店中的应用?

时间:2022-02-18 07:32:32

In the past, if I wanted to navigate directly to an app in the Google Play store from a PhoneGap app, I would do the following:

过去,如果我想通过PhoneGap应用直接导航到Google Play商店中的应用,我会执行以下操作:

location.href = 'market://details?id=my_package.my_app_name'

Now if I try to do that in my Cordova app (I'm now using Cordova 4.1.2), it just picks it's nose (no errors, just silently fails to navigate there).

现在,如果我尝试在我的Cordova应用程序中执行此操作(我现在使用Cordova 4.1.2),它只是选择它的鼻子(没有错误,只是默默无法在那里导航)。

I've verified that it is reaching the code before and after location.href = "...".

我已经验证它是在location.href =“...”之前和之后到达代码。

Does Cordova now have a new/different way of navigating to the google store? or new required permissions? Or is it just not possible anymore?

科尔多瓦现在有一种新的/不同的方式导航到谷歌商店吗?或新的必要权限?或者它再也不可能了?

3 个解决方案

#1


2  

You can use cordova app browser.

您可以使用cordova app浏览器。

https://github.com/apache/cordova-plugin-inappbrowser/blob/master/doc/index.md

https://github.com/apache/cordova-plugin-inappbrowser/blob/master/doc/index.md

code

var ref = window.open('http://apache.org', '_blank', 'location=yes');
var ref2 = window.open(encodeURI('http://ja.m.wikipedia.org/wiki/ハングル'), '_blank', 'location=yes');

#2


3  

Cordova added some security changes that don't allow to navigate to some links like you did before.

Cordova添加了一些安全性更改,无法像以前那样导航到某些链接。

Now you have two options to open other app:

现在您有两个选项可以打开其他应用:

Fist one, as mentioned by Dato, inAppBrowser plugin

正如Dato所提到的那样,第一个是inAppBrowser插件

Install it:

安装它:

cordova plugin add org.apache.cordova.inappbrowser

use it with _system option:

与_system选项一起使用:

window.open('market://details?id=my_package', '_system');

or:

要么:

window.open('http://play.google.com/store/apps/details?id=my_package', '_system');

Other option it to whitelist the url

其他选项将白名单列入白名单

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

http://cordova.apache.org/docs/en/4.0.0/guide_appdev_whitelist_index.md.html

http://cordova.apache.org/docs/en/4.0.0/guide_appdev_whitelist_index.md.html

#3


0  

What Dato meant with his answer is: you can use cordova app browser and then point the link to a play store application, which will open automatically (just like an add of other apps inside some apps).

Dato的回答是:你可以使用cordova app浏览器,然后将链接指向一个Play商店应用程序,该应用程序将自动打开(就像在某些应用程序中添加其他应用程序一样)。

His code is correct.

他的代码是正确的。

#1


2  

You can use cordova app browser.

您可以使用cordova app浏览器。

https://github.com/apache/cordova-plugin-inappbrowser/blob/master/doc/index.md

https://github.com/apache/cordova-plugin-inappbrowser/blob/master/doc/index.md

code

var ref = window.open('http://apache.org', '_blank', 'location=yes');
var ref2 = window.open(encodeURI('http://ja.m.wikipedia.org/wiki/ハングル'), '_blank', 'location=yes');

#2


3  

Cordova added some security changes that don't allow to navigate to some links like you did before.

Cordova添加了一些安全性更改,无法像以前那样导航到某些链接。

Now you have two options to open other app:

现在您有两个选项可以打开其他应用:

Fist one, as mentioned by Dato, inAppBrowser plugin

正如Dato所提到的那样,第一个是inAppBrowser插件

Install it:

安装它:

cordova plugin add org.apache.cordova.inappbrowser

use it with _system option:

与_system选项一起使用:

window.open('market://details?id=my_package', '_system');

or:

要么:

window.open('http://play.google.com/store/apps/details?id=my_package', '_system');

Other option it to whitelist the url

其他选项将白名单列入白名单

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

http://cordova.apache.org/docs/en/4.0.0/guide_appdev_whitelist_index.md.html

http://cordova.apache.org/docs/en/4.0.0/guide_appdev_whitelist_index.md.html

#3


0  

What Dato meant with his answer is: you can use cordova app browser and then point the link to a play store application, which will open automatically (just like an add of other apps inside some apps).

Dato的回答是:你可以使用cordova app浏览器,然后将链接指向一个Play商店应用程序,该应用程序将自动打开(就像在某些应用程序中添加其他应用程序一样)。

His code is correct.

他的代码是正确的。