H5+ app Vue calls third-party applications, if no installation jumps to app market details

1. Call a third-party application to determine if it is installed


pname is the Android application package name, action is the URL Scheme when ios is called, returns boolean

2. Determine if the current device is Android or ios

plus.os.name === "Android"
plus.os.name === "iOS"

3. Call third-party applications

plus.runtime.launchApplication( {pname:pname}, function ( e ) {
                  _this.$toast( "Open system default browser failed: " + e.message );
                } );
plus.runtime.launchApplication( {action:action}, function ( e ) {
                  _this.$toast( "Open system default browser failed: " + e.message );

4. If you don't have the app installed, open the local app store and the Apple system opens the APP store directly. Here's an example of opening the Golden Map

 _this.$confirm('You haven't installed the app yet,Whether to go to the App Store to download').then(res=>{
                    if ( plus.os.name === "Android" ) {
                      _this.getDeviceAppStore();// Get App Stores
                        if(_this.pname === ''){_this.$toast({message:'Sorry, your app store was not detected',type:'waring'});return;}
                        plus.runtime.openURL( "market://details?id=com.autonavi.minimap", function (e) {
                          _this.$toast('Failed to open')
                    } else if ( plus.os.name === "iOS" ) {

getDeviceAppStore(){// Get the device's app store package name, for Android
          let _this = this;
            if ( plus.os.name === "iOS" )return;
            // Get the current device manufacturer
            let vender = plus.device.vendor;
            // Obtain the package name of the app store from the device manufacturer, or give the user a list of third-party app markets if no device manufacturer is available
            switch (vender){
              case 'HUAWEI':
              case 'HONOR':
                _this.pname = 'com.huawei.appmarket';// Huawei, Glory
              case 'ONEPLUS':
              case 'OPPO':
                _this.pname = 'com.oppo.market';// OPPO, One Plus
              case 'VIVO':
                _this.pname = 'com.bbk.appstore';// vivo
              case 'MEIZU':
                _this.pname = 'com.meizu.mstore';// Meizu
              case 'XIAOMI':
                _this.pname = 'com.xiaomi.market';// millet
              case 'LENOVO':
                _this.pname = 'com.lenovo.leos.appstore';// association
              case 'ZTE':
                _this.pname = 'zte.com.market';// ZTENDING
              case 'XIAOLAJIAO':
                _this.pname = 'com.zhuoyi.market';// ZOYI
              case '360':
                _this.pname = 'com.qihoo.appstore';// 360 Qihu
              case 'NUBIA':
                _this.pname = 'com.nubia.neostore';// Nubian
              case 'MEITU':
                _this.pname = 'com.android.mobile.appstore';// Meitu
              case 'SONY':
                _this.pname = 'com.android.vending';// Sony
              case 'GOOGLE':
                _this.pname = 'com.android.vending';//Google
              // case 'HTC':
              // case 'ZUK':
                _this.pname = '';

In summary, when we click on the Open Golden Map button, we will first determine if it is installed or not, then what system is the current device, if {Android is installed according to package namePname, IOS opens the Golden Map according to the urlSecheme path}. If you don't have {Android installed, go to the current device manufacturer, get the package name of each manufacturer's APP store, open the Golden Map in the APP Store details page; IOS opens directly according to the download address (APP download address under iOS can find the APP to download in the APPStore, click Share to get the download address link,Bring it over)}

5. Call the mobile app market, if Android has only one app market open directly, if there are more than one, it will pop up a window to choose from and ios will open the APP Store directly

            if (plus.os.name === "iOS") {
            else if (plus.os.name === "Android") {
              let Uri = plus.android.importClass("android.net.Uri");
              let uri = Uri.parse("market://details?id=" + 'com.tencent.mm' );
              let Intent = plus.android.importClass('android.content.Intent');
              let intent = new Intent(Intent.ACTION_VIEW, uri);
              let main = plus.android.runtimeMainActivity();

The code above takes the example of opening WeChat and replaces it with the application you want to open, which is uploaded in https://ask.dcloud.net.cn/article/114 This is what the great gods are about Native.js Summary of some applications in Android and ios

6. Call a third-party program to navigate, Android will get all the navigation applications installed on the device, pop-up window selection box, if only one opens directly, ios opens the system navigation application (Golden)

                // Setting coordinate points of target position and starting position
                let dst = new plus.maps.Point(116.39131928,39.90793074); // Tiananmen
                let src = new plus.maps.Point(116.335,39.966); // Great Bell Temple
                // Call System Map Display
                plus.maps.openSysMap( dst, "Tiananmen", src );



Tags: Android iOS Mobile Google

Posted on Mon, 15 Jun 2020 21:47:00 -0400 by jeet_0077