-1

I'm building an app with NativeScript 6.4.1 and Angular 8.

We want to be able to disable and enable the hardware controls of the phone at will. I need to be able to do that for both iOS and Android.

I want to disable the back button, the home button etc. all the buttons that could be at the bottom of the device.

I have tried to look through the documentation and I could not find a way to do this: https://docs.nativescript.org

How can I do that?

user1261710
  • 2,539
  • 5
  • 41
  • 72
  • Sorry, unclear what you are asking. The documentation you have linked is about accessing device info. What kind of hardware controls you are talking about, please be more specific, possibly with an example. – Manoj Apr 17 '20 at 14:50
  • I want to disable the back button, the home button etc. all the buttons at the bottom of the device. – user1261710 Apr 17 '20 at 14:51
  • 1
    You can not disable hardware buttons, but you can override the behavior. We have back button (`activityBackPressed`) event out of the box, you can decide wether the app / page should be closed or do nothing - https://docs.nativescript.org/core-concepts/application-lifecycle#android-activity-events If you want to override home / menu button, you will have to create your own activity and override keydown callback - [Here is how you do it in native android](https://stackoverflow.com/questions/5547818/can-i-override-the-home-button-in-my-application), could be ported to {N}. – Manoj Apr 17 '20 at 15:24
  • @Manoj if you put it in an answer I will upvote the answer. – user1261710 Apr 20 '20 at 07:57

1 Answers1

1

You can not disable hardware buttons, but you can override the behavior. We have back button activityBackPressed event out of the box, you may decide wether to cancel the default behavior and perform your own action.

If you want to override home / menu button, you will have to create your own activity and override keydown callback. Here is how you do it in native android, could be ported to {N}.

Manoj
  • 21,753
  • 3
  • 20
  • 41