Unable to change android back button default action


#1

I’ve been trying to override the default action of android’s back button in my ionic app but not able to do that. I’ve tried almost every piece of code listed on this page Handling the hardware back buttons , the most recent being -

$ionicPlatform.registerBackButtonAction(function(event) {
    if (true) { // your check here
      $ionicPopup.confirm({
        title: 'System warning',
        template: 'are you sure you want to exit?'
      }).then(function(res) {
        if (res) {
          ionic.Platform.exitApp();
        }
      })
    }
  }, 1000);

And this too doesn’t make any difference to android’s default action.
I am using ‘ionic run android’ to install the app on phone. Please help me with this.