How to detect browser and mobileweb platform using Ionic 4 because when I tried with below code in desktop browser it is not falling in ‘core’ condition.
<The following link may help you:
https://forum.ionicframework.com/t/how-to-determine-if-browser-or-app/89149/16
or you can use the following method:
public isDesktop() {
let platforms = this.plt.platforms();
if(platforms[0] == "core" || platforms[0] == "mobileweb") {
return true;
} else {
return false;
}
}
In case anyone is still struggling with this on ionic4/cordova, I solved it using
import {Device} from '@ionic-native/device/ngx'
Just add it into your app.modules and run this.device.platform wherever you need to find out, to give an idea, the output on web and apk from this simple code
console.log(this.platform.platforms());
console.log(this.device.platform);
is this:
Running on web (desktop and mobile)
["android", "phablet", "cordova", "mobile", "hybrid"]
browser
Running android local (apk)
["android", "cordova", "desktop", "hybrid"]
Android
Now I can correctly use the plugins for browser or mobile correctly, in my case is image loading and cropping.
A full explanation can be found at https://www.damirscorner.com/blog/posts/20171124-DetectingWhereIonicAppIsRunning.html