In the document I find this statement
The hardware back button is found on most Android devices. In native applications it can be used to close modals, navigate to the previous view, exit an app, and more.
By native applications, does that mean the compiled ionic apps?
So yes, the physical back button will do the modalController.dismiss()
or no, I have to subscribe it myself.
A native application is considered an Ionic app compiled with Capacitor running on a device (iPhone or Android, physical or emulator). If you are just running your Ionic app in a web browser, then it’s not a native app.
Yes, the hardware back button on Android should close the modal for you. The back gesture on Android does as well (what has replaced the hardware back button on many Android devices).
Say I run the Ionic app on web browser at mobile phone, the physical back button will act as the browser back button.
And in that case, the modal dismiss will not in default happens?
Also, will I override the default native app physical back button behaviour if I implement the call back ?
this.platform.backButton.subscribeWithPriority(10, () => {});
I just tested on a Pixel 3 running in Chrome normally and as a PWA (added to Home screen) and the back gesture acts as back in the browser so it doesn’t dismiss the modal. So, it appears it has to be installed and running as a native app to work.
Though, it does appear there is an experimental feature to support it in web and PWAs - see Hardware Back Button for Capacitor & Cordova on Android Devices.
Yes, you can override the back button behavior using this.platform.backButton.subscribeWithPriority
.