Is it possible to block the S Pen Air Command menu from opening with the pen button press in my application in Android Studio?

25 views Asked by At

I'm developing an Android application in Kotlin, and I'm encountering an issue related to the S Pen functionality on Samsung devices. Specifically, I want to prevent the Air Command menu from opening when the user presses the button on the S Pen.

I've searched extensively but haven't found a clear solution. Is there a way, either through Android Studio or via code, to intercept or block the default behavior of the S Pen button press that opens the Air Command menu while the user is using the app?

Any insights, suggestions, or code examples would be greatly appreciated.

I tried to override the onTouchEvent method to ignore touch events specifically triggered by the stylus button press, but it didn't work:

override fun onTouchEvent(event: MotionEvent): Boolean {
// Ignore the click event from the stylus button or if the user is not using the pen
if (event.buttonState and MotionEvent.BUTTON_STYLUS_PRIMARY != 0 ) {
    // Return true to indicate that the event has been handled
    return true
}
0

There are 0 answers