I play with keyboard design and try to show a popup dialog when a certain key is pressed
if (primaryCode == -301) {
AlertDialog mDialog = new AlertDialog.Builder(CONTEXT)
.setTitle("My dialog")
.setMessage("Lets do it.")
.setPositiveButton("ok", null).create();
mDialog.show();
}
However, the problem is part CONTEXT. In a regular application, it will be simple this. I also tried getApplicationContext()and getBaseContext(), but none of these work -> keyboard crash.
android.view.WindowManager $ BadTokenException: Unable to add window null token not for application
So, I am wondering if I need to do something with InputConnection :
The InputConnection interface is a communication channel from InputMethod back to the application that receives its input. this is used to accomplish such things as reading text around the cursor, fixing text in the text box, and sending raw key events to the application.
Until now, I could not figure out how to do this. I definitely know that this is possible since I saw it before. I could point me in the right direction, which would definitely be appreciated.
Update:
To provide a better idea of ββwhat I'm trying to achieve, I downloaded a screenshot of the Swype keyboard, which does just that: displaying a popup when a special key is pressed on the keyboard.

source
share