Ionic native device plugin returns all nulls in all platforms

238 Views Asked by At

I'm using @ionic-native/device plugin in my ionic application in order to detect the underlying device running the application. However, when I try to use it I get the Device object with all properties set to null.

Note: this is NOT a duplication of This question since the problem occurs even when running cordova run browser or running in android...

I've installed the @ionic-native/device plugin and used it as follows:

App.module.ts:

import { Device } from '@ionic-native/device/ngx';

@NgModule({
// ...
providers: [
    Device,
]
//...
})
export class AppModule { }

App.component.ts:

 constructor(private device: Device) {
    console.log('Device is: ', this.device);
 }

package.json:

"dependencies": {
  ...
    "@ionic-native/core": "^5.24.0",
    "@ionic-native/device": "^5.26.0"
 }

What is missing?

1

There are 1 best solutions below

0
On

i suggest you to try this since, the method ready of the platform object helps you to wait all the plugins to be ready in order to execute your code. don't forget this in your constructor params list : "private platform : Platform"

this.platform.ready().then(()=>{
    console.log('Device is: ', this.device);
}