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);
}
Related
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!
ive got another Question for you.
So im trying to get the user input working on an options menu. For this i got:
1. The Stage and
2. An extra Inputadapter
I need the extra Inputadapter to catch the BACK key on Android. So i have used an Inputmultiflexer, which allows me to use both inputprocessors.
InputMultiplexer multiplexer = new InputMultiplexer();
multiplexer.addProcessor(this);
multiplexer.addProcessor(stage);
Gdx.input.setInputProcessor(multiplexer);
Gdx.input.setCatchBackKey(true);
And my method to check for the BACK button looks like this:
#Override
public boolean keyUp(int keycode){
if(keycode == Input.Keys.ESCAPE || keycode == Input.Keys.BACK){
new MenuScreen(game);
return true;
}
return false;
}
The problem: Its not working at all. It does not go back, when using the Back key on Android or the Escape key on Desktop. The only thing the Console is printing out when pressing the Button is :
Load KCM of non-default device may incur unexpected result
To be honest, i have no idea what its means and Google didnt help me either with that.
So how do i get this to work?
First when debugging, you should use something like :
System.out.println("back was pressed");
If you see that output in the console then you know input is working. If that works, the only problem I see with your code is that you may have created a new screen class, you never made it switch screens. I noticed you passed in the game object, so you should probably have something like this:
game.setScreen(new MenuScreen(game));
Hope this helps.
I need to get some information from the on screen keyboard such as pressure, KeyDown and KeyUp in Android but don't know how to do that.
The android official site says that:
Note: When handling keyboard events with the KeyEvent class and
related APIs, you should expect that such keyboard events come only
from a hardware keyboard. You should never rely on receiving key
events for any key on a soft input method (an on-screen keyboard).
I also tried the following method without success. It actually works with the hardware keys like back button.
myEditText.setOnKeyListener(new View.OnKeyListener() {
#Override
public boolean onKey(View view, int i, KeyEvent keyEvent) {
return false;
}
});
I was thinking of finding a way of extending the on screen keyboard, but still no success!
Does anyone have ever tried doing this? I'd appreciate your help in advance.
UPDATE:
After trying many solutions I came up with the same solution of using my own keyboard, suggested by krossovochkin, ultimately. It seems that the solution is not too bad if one wants to modify the Android's keyboard as a new one. This way, it appears in the "Settings --> Input Methods" so that the user can switch to the new keyboard, which is good since it is accessible from all other apps. Since it is not yet clear that whether it is possible to get the pressure from the standard virtual keyboard, therefore I thought the question could be left open.
You can try to call getPressure() method from MotionEvent
Link: http://developer.android.com/reference/android/view/MotionEvent.html#getPressure%28int%29
Code snippet:
view.setOnTouchListener(new View.OnTouchListener() {
#Override
public boolean onTouch(View v, MotionEvent event) {
float pressure = event.getPressure();
}
});
UPDATE:
You can create your own keyboard and getPressure from it.
Maybe user will not like using your keyboard instead of his default keyboard.
But I think this is the best solution for your situation.
More information about:
KeyboardView: http://developer.android.com/reference/android/inputmethodservice/KeyboardView.html
Example of creating your own keyboard:
https://github.com/rciovati/Android-KeyboardView-Example
I have an issue in Android Jelly Bean version where the web view refuses input in text boxes.
Tried with a simple page with only one input tag as given below.
In android browser the page works fine, both keypress and blur events fire.
In Web view only the blur event fires and the text is not appearing.
I tried the webview settings mentioned in the link given below.
Why is Android WebView refusing user input?
There is a known defect in jelly bean for text fields with 'maxlength' attribute. I am not using max length .
<input id="phoneNumber"
name="phoneNumber" type="text" value="test" onblur="alert('lost focus');" onkeypress="alert('key press');"/>
Can anyone throw some light on how to resolve this issue??
I had the same problem and my research results with this:
As there is devices with no physical buttons, there is the navigation Bar with the relevant buttons.
So, if a physical 'back' button was pressed the onKeyDown method was called, and i guess they had to attach this method to the 'back' button on the Navigation Bar.
Any way, it results with the call to the onkeyDown and onkeyUp methods when the soft keyboard is being used, and if for some reason you override it you have to make sure you call super so it will be able to process the keys event:
#Override
public boolean onKeyDown(int keyCode, KeyEvent event)
{
if (keyCode == KeyEvent.KEYCODE_BACK)
{
// Do Somthing...
return true;
}
return super.onKeyDown(keyCode, event);
}
Hope it helps.
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.