I'm trying to make an app which is controlled by a gamepad. I've gotten it to work alright, but Android has some default controls that it uses for navigation when a gamepad is plugged in, such as the B button takes you back a menu. I want to be able to use the buttons that Android has defaults for. Is there a way to disable the default Android controls? I can't find any thing about the default Android gamepad controls, let alone how to disable them.
I figured it out. For anyone who needs this in the future, here's how to do it. When you add in the onKeyDown override command, this is what it looks like.
#Override
public boolean onKeyDown(int keyCode, KeyEvent event)
{
return super.onKeyDown(keyCode, event);
}
As I understand it, that return line gives the Android system access to the button presses. However if you make it always return true, the Android system never sees the input. For example:
#Override
public boolean onKeyDown(int keyCode, KeyEvent event)
{
if(keyCode == KeyEvent.KEYCODE_BUTTON_A)
{
buttonAPressed = true;
}
return true;
}
I don't know if this is the best way to do it, but that's my work around to it. Hope this helps anyone that needs it!
Related
I'm using chineese printer. It has OS android and also it has a few buttons, on of them is "scan". When I press it I don't see anything in system log. How can I find out the code of this button?
Already tried to find something in logs but didn't see anything related to this button. I even tried not my app log, but system log didn't help. I don't know if this button is working or not
It seems like they used button scan instead of button "menu"
I tried this code and
public boolean onKeyUp(int keyCode, KeyEvent event) {
Log.e("KeyCode",keyCode+"");
if (keyCode == KeyEvent.KEYCODE_MENU) {
Log.e("KeyCode",keyCode+"");
return true;
} else {
return super.onKeyUp(keyCode, event);
}
}
and i got two times
03-24 08:33:41.429 E/KeyCode﹕ 82
03-24 08:33:41.429 E/KeyCode﹕ 82
It means it has the same keycode as Menu button
How can I track the keys pressed by the user in keyboard in android?
Is this possible or I have to create a keyboard myself?
What could be the possible way ?
Please check Creating An Input Method. This would help you in creating a custom Input Method. You can check the Sample Application in your Android SDK directory. Please follow as per this link.
One way to liste for those is:
#Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK) {
// Log the Key that was pressed or do whatever you need
// keyCode contains all the possible keyCode presses
}
else if(keyCode == KeyEvent.KEYCODE_1){
//You can insert catches for each particular keypress here
}
return super.onKeyDown(keyCode, event);
}
All the codes are here in this LINK, take a look at them.
I'm developing a simple app on PhoneGap for an Android set top box.
I have an image that is usable as a link. When I connect a mouse to the set top box and click the image, the link works. But when I use the remote control and select the image (I see the border around the image so I know it is selected) and I click OK button, the link does not work.
How can I use the remote buttons in the code?
This is very tricky because Google didn't feel like mapping the keys on a remote to an actual key output.
To use the setTopBox, you're going to have to figure out what key codes your Android Set Top Box is using and modify the Activity's onKeyUp event to handle it. We currently have an example of a work-around in this bug however we don't have an agreed API for exposing these buttons to Javascript yet, which is why this bug is still open.
But in short, you'd do something like this:
#Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_DPAD_UP)
{
sendJavascript("javascript:myJsMethod('UP');");
return true;
}
return super.onKeyDown(keyCode, event);
}
I'm developing an application right now and I need to disable the quick-search-box as somehow it dismisses my dialog boxes that request info to keep people who are not supposed to be using my application out [its in development, and its on the market - it makes it much easier to keep people up to date]. Listeners for all types of dismissing dialogs are never triggered - and I don't know why. I've looked everywhere and I get no result on how to disable this. (2.1 and up).
How to disable QSB..? was a good start, but it doesn't work. I don't know why google insists I use this... I have absolutely no need for this in my application.
How can I go about fixing this... or do I have to try another sort of DRM?
You can block the search on your activity or dialog by implementing this and returning false:
public boolean onSearchRequested() {
return false;
}
UPDATE:
Code works on dialogs, too
public boolean onKeyDown(int keyCode, KeyEvent event) {
if(keyCode==KeyEvent.KEYCODE_SEARCH && event.getRepeatCount() == 0)
{
return true;
}
else
{
return false;
}
}
Returning true means that we are handling the Search Event.
I am new to Android development and having a problem with what SHOULD be a very simple task. I want to receive KeyEvents whenever a user is typing in an EditText field because I want to save their entered values to data structures in the background on each key stroke.
I have mimic'd the code in the Beginner's Dev guide at http://developer.android.com/resources/tutorials/views/hello-formstuff.html#EditText and set up an OnKeyListener. Here is a snippet of my code:
cell.amountEditText.setOnKeyListener(new View.OnKeyListener() {
public boolean onKey(View v, int keyCode, KeyEvent event) {
System.err.println("onKey for Amount, key="+event.getDisplayLabel());
if (event.getAction() == KeyEvent.ACTION_DOWN) {
return onKeyDownInAmount(finalPosition, (EditText)v, keyCode, event);
} else {
return false;
}
}
});
Behavior on the emulator is spotty at best, some times it will deliver the KeyEvents for the virtual keyboard, sometimes it won't. When I install the app on my device (HTC Hero which has a virtual keyboard only) then NONE of the events fire. I never receive a single KeyEvent.
What am I doing wrong?
Any help is appreciated.
The onKeyListener only receives events from a hardware keyboard. Use TextWatcher instead.