angulartypescriptnativescriptangular2-nativescript

How to open Play Store URL on button click in Angular2 nativescript


I need to open Play Store url with the help of Play Store app when clicking on button. I have many app urls from Play Store.

For Eg: https://play.google.com/store/apps/details?id=com.ninjakiwi.bftg

App's page should not open in the browser. It has to open in official Google Play Store app when clicking on button.


Solution

  • You can use app store link provided by Google. Ex:

    market://details?id=

    This way choose option will not come and directly open in playstore. Here id = your playstore appID ex: com.ninjakiwi.bftg (In your case)

    market:// Launches the Play Store app to load the target page.

    http:// Lets the user choose whether to launch the Play Store app or the browser to handle the request. If the browser handles the request, it loads the target page on the Google Play website.

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

    Okay. window.location.href will not work here. So here is the complete solution for you:

    You will have to use utils/utils module provided by Nativescript

    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");
        }
    }
    

    Here openURL function will be called on button Tap event from view. More: https://docs.nativescript.org/core-concepts/utils