Problem
Screen Orientation onChange does not work in Android 8.
I posted this issue in https://github.com/apache/cordova-plugin-screen-orientation/issues/54
The first answer was: This plugin doesn’t contain any Typescript code. Your problem is probably with the Ionic Native wrapper I guess you are using.
Error
ERROR TypeError: Invalid event target
at setupSubscription (vendor.js:92237)
at Observable._subscribe (vendor.js:92211)
at Observable.push…/node_modules/rxjs/_esm5/internal/Observable.js.Observable._trySubscribe (vendor.js:90333)
at Observable.push…/node_modules/rxjs/_esm5/internal/Observable.js.Observable.subscribe (vendor.js:90319)
at main.js:12388
at ZoneDelegate.push…/node_modules/zone.js/dist/zone.js.ZoneDelegate.invoke (polyfills.js:2753)
at Object.onInvoke (vendor.js:53422)
at ZoneDelegate.push…/node_modules/zone.js/dist/zone.js.ZoneDelegate.invoke (polyfills.js:2752)
at Zone.push…/node_modules/zone.js/dist/zone.js.Zone.run (polyfills.js:2512)
at polyfills.js:3251
Code
this.screenOrientation.onChange().subscribe(
() => {
//This code is never executed
if(this.screenOrientation.type==‘portrait-primary’){
this.useBigclass=false;
this.platformWidth=Math.min(platform.width(),platform.height());
}else{
this.useBigclass=true;
this.platformWidth=601;
}
console.log(“Orientation Changed”,this.screenOrientation.type);
}
Environment, Platform, Device
C:\ionic4\getfm5b>ionic info
Ionic:
Ionic CLI : 5.1.0 (XXXX\npm\node_modules\ionic)
Ionic Framework : @ionic/angular 4.6.0
@angular-devkit/build-angular : 0.13.9
@angular-devkit/schematics : 7.3.9
@angular/cli : 7.3.9
@ionic/angular-toolkit : 1.5.1
Cordova:
Cordova CLI : 9.0.0 (cordova-lib@9.0.1)
Cordova Platforms : android 8.0.0
Cordova Plugins : cordova-plugin-ionic-keyboard 2.1.3, cordova-plugin-ionic-webview 4.1.1, (and 20 other plugins)
Utility:
cordova-res : 0.3.0
native-run : 0.2.2
System:
Android SDK Tools : 26.1.1 (XXXX\Local\Android\android-sdk) NodeJS : v8.9.4 (C:\Program Files\nodejs\node.exe)
npm : 4.6.1
OS : Windows 10
Plugins
com.unarin.cordova.beacon 3.8.1 “Proximity Beacon Plugin”
cordova-plugin-app-version 0.1.9 “AppVersion”
cordova-plugin-background-mode 0.7.2 “BackgroundMode”
cordova-plugin-badge 0.8.8 “Badge”
cordova-plugin-ble-central 1.2.2 “BLE”
cordova-plugin-camera 4.0.3 “Camera”
cordova-plugin-compat 1.2.0 “Compat”
cordova-plugin-device 2.0.2 “Device”
cordova-plugin-file 6.0.1 “File”
cordova-plugin-filechooser 1.2.0 “File Chooser”
cordova-plugin-filepath 1.5.5 “cordova-plugin-filepath”
cordova-plugin-ionic-keyboard 2.1.3 “cordova-plugin-ionic-keyboard”
cordova-plugin-ionic-webview 4.1.1 “cordova-plugin-ionic-webview”
cordova-plugin-local-notification 0.9.0-beta.2 “LocalNotification”
cordova-plugin-nativeaudio 3.0.9 “Cordova Native Audio”
cordova-plugin-photo-library 2.2.1 “Photo Library”
cordova-plugin-printer 0.8.0 “Printer”
cordova-plugin-screen-orientation 3.0.1 “Screen Orientation”
cordova-plugin-splashscreen 5.0.2 “Splashscreen”
cordova-plugin-statusbar 2.4.2 “StatusBar”
cordova-plugin-whitelist 1.3.3 “Whitelist”
cordova-sqlite-storage 3.2.0 “Cordova sqlite storage plugin - cordova-sqlite-storage plugin version”
es6-promise-plugin 4.2.2 “Promise”
phonegap-plugin-barcodescanner 8.1.0 “BarcodeScanner”