简体   繁体   中英

Disabling the home button on a bluetooth keyboard programatically in an android application

I'm making an Android app using Xamarin and C#. The app will always be running in Kiosk-mode in which the bottom navigation bar of the device will be removed and navigation outside of the app is blocked.

However, when the user connects a bluetooth keyboard they can hit the physical home button and return to the android home screen which should not be accessible.

I'm aware that there are ways to disable the home button , but I haven't been able to get any of them to work properly as they're generally hacks since Android doesn't directly allow developers to intercept the home button.

Is there anyway I can remap the home key of bluetooth keyboards connected? Are there any other solutions to this that I maybe overlooking?

You can't intercept Android Home Button due to security of device, however if you have rooted device you can experiment with Android https://source.android.com/devices/input/key-layout-files.html https://source.android.com/devices/input/key-layout-files.html

But that requires root on device

  1. Another method with root is to find the correct /dev/input/eventX device, get exclusive access to it, and then use the /dev/uinput interface to create a new device. Then write all events from the keyboard other than home key to the new interface. I haven't tested this, but in theory it should work.

  2. You could perhaps create a dummy launcher that simply exits as soon as it starts. But it would disable the home button altogether, not just on the BT keyboard.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM