If you have deeplink
of the app, go with in App Browser.
I have achieved app triggering functionality using cordova-plugin-app-launcher.
I believe same can be achieved by com.lampa.startApp.
Below are steps taken by me -
- Include to project -
cordova plugin add cordova-plugin-app-launcher
- Install package -
npm install cordova-plugin-app-launcher
. No need for cordova prepare
command.
To avoid blocking compilation error (due to cordova), I have created a start-app.js
file with following contents -
module.exports = {
packageLaunch: function(appSchemeStr){
// launch app using package name (for Android devices)
window.plugins.launcher.launch({
packageName: appSchemeStr
},
function(){ },
function(){ alert('Failed to open app') }
);
},
uriLaunch: function(appUriStr){
// launch app using URI (for iOS devices)
window.plugins.launcher.launch({
uri: appUriStr
},
function(){ },
function(){ alert('Failed to open app') }
);
},
}
Now import start-app.js
in required *.ts
file -
import * as launcher from '../../assets/js/start-app';
And now to launching app using package name -
launcher.packageLaunch("com.company.appName"); // replace with correct package name
Along with above code, include Launcher.js
created after npm install
command under \node_modules\cordova-plugin-app-launcher\www\
folder to index.html
just after cordova.js
-
<script src="assets/js/Launcher.js"></script>
Above code works perfectly in devices, but for web, ionic serve
command generates warning error message due to Launcher.js
as cordova.js
is not present, but works there as well when ignored.
To solve that, I have added conditional include statement for Launcher.js
in head of index.html
.
As this feature is not required in web version, I am only including it in mobile device .
In your *.ts
file (mine is home.ts) -
import { Device } from '@ionic-native/device';
export class HomePage{
constructor(public device: Device) { }
ionViewDidEnter(){
if(this.device.cordova){
// This is a mobile device, add app-launcher script in head
var head = document.getElementsByTagName('head')[0];
var scriptTag = document.createElement("script");
scriptTag.src = "assets/js/Launcher.js"; // script for launching apps
head.appendChild(scriptTag);
}
}
}
I have confirmed that -
ionic serve
,
ionic cordova build android --prod
,
ionic cordova run browser
and
npm run build --prod
work perfectly.