Jump to third-party app for Cordova plug-ins

created by diwj on 20171205 Step 1: Install the Cordova plug-in cordova plugin add https://github.com/lampaa/com.lampa....
created by diwj on 20171205

Step 1: Install the Cordova plug-in

cordova plugin add https://github.com/lampaa/com.lampa.startapp.git //Non-cordova official plug-in, open third-party app s cordova plugin add cordova-plugin-appavailability --save//Detect the existence of third-party app s cordova plugin add cordova-plugin-inappbrowser //Apply built-in browser





Step 2:Config.xmlNeed to configure permissions


1.ios configuration
Note: As long as there are ipa files, changing the suffix name to zip can be used as zip decompression. After decompression, you can see the.plist file. If you see the file scrambled, you can download plistEditor or related tools to view it

<allow-intent href="A://*/*" /> //A Is Scheme Name, corresponding to CFBundleURLSchemes in the.plist file <allow-intent href="B://*/*" /> //B is AppName, corresponding to CFBundleName in the.plist file



2.android Configuration

<allow-intent href="C://*/*" /> //C is the scheme of app





Step 3: Decide which platform your system belongs to and execute different codes

//You must install the cordova-plugin-device plugin order to use the following judgment var scheme; if(device.platform === 'iOS') { //ios scheme="A"//A Ibid. iosCheck(scheme) } else if(device.platform === 'Android') { //android scheme="D"//D is Package Name androidCheck(scheme) }



Step 4: Detect if the app exists, open if it exists, and open the download link if it does not exist


1. Implementation of iosCheck method

function iosCheck(scheme){ appAvailability.check( scheme, // URI Scheme or Package Name function() { // Success callback alert(scheme + ' is available :)'); var sApp = startApp.set(scheme); sApp.start(function() { /* success */ //alert("OK"); }, function(error) { /* fail */ //alert(error); }); }, function() { // Error callback console.log(scheme +"Not available") var confirmPopup = $ionicPopup.confirm({ title: 'Friendship Tips', template: 'You have not installed the app,Is it installed', cancelType:'item-customer-bg-lightred', okText: 'go AppStore', okType:'item-customer-bg-darkred', cancelText:'Don't install yet', cancelType: 'item-customer-bg-lightred' }); confirmPopup.then(function(res){ if(res){ console.log("Installation in progress......") window.open('Download Link Address') }else{ console.log("Cancel Installation......") } }); } ); }



2. Specific implementation of androidCheck method

function androidCheck(sheme){ appAvailability.check( scheme, // URI Scheme or Package Name function() { // Success callback console.log(scheme + ' is available :)'); var sApp = startApp.set({ /* params */ "action":"ACTION_MAIN", "category":"CATEGORY_DEFAULT", "type":"text/css", "package":sheme, "uri":"file://data/index.html", "flags":["FLAG_ACTIVITY_CLEAR_TOP","FLAG_ACTIVITY_CLEAR_TASK"], // "component": ["com.android.GoBallistic","com.android.GoBallistic.Activity"], "intentstart":"startActivity", }, { /* extras */ "EXTRA_STREAM":"extraValue1", "extraKey2":"extraValue2" }); sApp.start(function() { /* success */ console.log("open success") }, function(error) { /* fail */ console.log("open failed") }); }, function() { // Error callback console.log(scheme + ' is not available :('); } ); }





Finally, a whitelist is required in ios9+, otherwise it cannot be detected

<key>LSApplicationQueriesSchemes</key> <array> <string>A</string> <string>B</string> </array> //AB means the same thing, configuring the path platforms/projectName/XXX-Info.plist

15 July 2020, 11:40 | Views: 4403

Add new comment

For adding a comment, please log in
or create account

0 comments