如何在单击angular2本机脚本时打开按钮上的playstore应用程序URL

Luf*_*ffy 3 typescript nativescript angular2-nativescript angular

单击按钮时,我需要在playstore应用程序的帮助下打开playstore应用程序URL。我有来自Playstore的许多应用程序网址。

例如: https //play.google.com/store/apps/details?id = com.ninjakiwi.bftg

应用程序不应在浏览器的帮助下打开。单击按钮时,它必须在官方google playstore应用程序的帮助下打开。

Man*_*mar 5

您可以使用Google提供的应用商店链接。例如:

market:// details?id =

这种选择选项不会出现,而是直接在Playstore中打开。此处的ID =您的Playstore AppID,例如:com.ninjakiwi.bftg(针对您)

market:// 启动Play商店应用以加载目标页面。

http://, 让用户选择是启动Play商店应用还是浏览器来处理请求。如果浏览器处理了该请求,它将在Google Play网站上加载目标页面。

参考:https : //developer.android.com/distribute/marketing-tools/linking-to-google-play.html

好的。window.location.href在这里不起作用。因此,这是为您提供的完整解决方案:

您将必须使用Nativescript提供的utils / utils模块

import { Component, OnInit } from "@angular/core";

import * as utils from "utils/utils";

@Component({
    selector: "ns-details",
    templateUrl: "./item-detail.component.html",
})
export class ItemDetailComponent implements OnInit {

    constructor(
    ) { }

    ngOnInit(): void {
    }

    openURL() {
        utils.openUrl("market://details?id=com.ninjakiwi.bftg");
    }
}
Run Code Online (Sandbox Code Playgroud)

在这里,从视图的按钮Tap事件中将调用openURL函数。 更多:https//docs.nativescript.org/core-concepts/utils