Doesn't recognize MEDIA_BUTTON Trigger on Beats Solo - android

I tried both the Intent-receiver and the onKeyDown Method. Both work fine for most buttons but the Beats Solo Headset has multiple Buttons and only the Play Button is detected, the + / - Buttons don't trigger the Receiver nor they trigger onKeyDown().
Any ideas?

Ok, I found the problem in the AOSP Tech Specs. There are a lot of HID Interactions that aren't defined for Android. So I will try to read out the HID code with a scope and map this Key to Android.
Android AOSP // KEYBOARD
EDIT: I connected them to the scope while a menu button press is clearly visible, the + amplitude is pretty small and - is nearly indetectable. I attached both scope screenshots. If anyone has found a solution then contact me please.
NOTE: the screenshot shows the menu button pressed 3 times!

Related

Detect/override controller "Home" button press android

I have an android application that is meant to be used with a game controller connected to the android device.
Most game controllers have a center 'home' button that I would like to use to pause the game (for example, an Xbox controller center nexus button should pause).
However, when you press the center nexus button on the controller it causes the entire app to close as though the actual home button on the phone was pressed. Why is the center button on some controllers causing the app to return to the home screen? Note, this doesn't happen with all controllers or all devices. For example, using a pixel 6 and an xbox controller it doesn't send the app home. But using a galaxy a32 the center nexus button does triggers the home action.
I understand its not possible to intercept the actual home action from within an app. But is it possible to do so from a physical controller? Or is it possible to remap the controller buttons?
I tried this in an attempt to intercept the home action:
#Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
Log.e("KeyPress", "Code: " + keyCode);
switch (event.getKeyCode()){
case KeyEvent.KEYCODE_HOME:
return false;
default:
return super.onKeyDown(keyCode, event);
}
}
but this isn't working. Pressing the center button on the controller doesn't trigger the log but it still goes to the home screen.
Any ideas how to make certain button on physical controllers not trigger the home action?
Thanks
This happens with gamepads that send the same input code used for the "Homepage" key on some keyboards. By default, HID input devices are handled by the hid-input driver which always translates the "Consumer Application Control Home" usage (000C:0223) to the KEY_HOMEPAGE Linux input event code.
https://github.com/torvalds/linux/blob/4e23eeebb2e57f5a28b36221aa776b5a1122dde5/drivers/hid/hid-input.c#L1151
The Android OS converts KEY_HOMEPAGE to KeyEvent.KEYCODE_HOME which is handled by the framework and never delivered to applications. Probably it should convert it to BTN_MODE as suggested by the Linux gamepad specification.
If you have root access you can fix this by adding a Key Layout file to correct the button mapping for a specific device. See Vendor_045e_Product_02fd.kl for an example of a key layout file that maps KEY_HOMEPAGE (Linux input event code 172) to Android's KeyEvent.KEYCODE_BUTTON_MODE.

Android: How to trigger any key pressing event on soft keyboard?

Is there any way to press key of Android Soft Keyboard programmatically.
Like: When keyboard will appear, I want to press "J" key through my code not from fingers.
First method:
IBinder binder = ServiceManager.getService("window");
IWindowManager manager = IWindowManager.Stub.asInterface(binder);
manager.injectKeyEvent(new KeyEvent(KeyEvent.yourAction, KeyEvent.yourKeyCode),true);
You can see more details here.
There is another method in this link too.
Second method, using instrumentation:
Instrumentation inst = new Instrumentation();
inst.sendKeyDownUpSync(KeyEvent.KEYCODE_MENU);
And you can see this question that explains how to use instrumentation and webview to do that.
You don't need the keyboard to do this, you can show it or not.
A list of keyCodes if you want.
This link will show keyCode for every key that you press, I think it works with the android and linux keyboards, but don't know if the code will be the same using another OS.

Qt5 (c++) android listening for system buttons

I want to use the menu button in my android app (4.x so usually software, not hardware buttons) but I can't find a suitable QEvent to do so. I tried to do
bool GLViewer::event(QEvent * e){
qDebug()<<e->type();
}
But pressing the menu button had no output, I'm assuming because the menu button is outside the widget. How do I listen for this type of event?
As read on this post, you can use the keyReleaseEvent() on your main window.

Is it possible to listen for touches on the physical Android back button?

I couldn't find it in the docs, is there a module, or some other way to catch events from the android back button? If not it would be a nice and probably quick module to add.
No: the back button just pops you one item back in the history stack. You do something like change the hash fragment to track navigation through your app (frameworks like Backbone.js can do this for you automatically).
The reason we've taken that approach is there's no hardware back button on iOS so we're wary of setting people up to rely on it in their app, only for the app to be fundamentally broken on that platform: we're aiming for consistency of completeness at the moment.
Update: due to popular demand, we've added support for controlling the back button behaviour on Android: http://docs.trigger.io/en/v1.4/modules/event.html#backpressed-addlistener - note backPressed.preventDefault too.
The event handler is passed a function which, when invoked, closes the app, so you could have code like:
forge.event.backPressed.addListener(function (close) {
if (atHomeScreen) {
close();
}
}

Android back-button-overriding etiquette / guidelines

I have an app in which the user logs in from a main activity, and then can browse through a heirarchy of entities using listviews. So, the Activity stack would look something like this:
A -> B -> B -> B -> ...
where the number of B's is proportional to how deep you are in the tree of entities.
Frequently, I find myself pressing backbackbackbackback to get to the root (the first 'B'), but one too many presses and I log myself out, or even leave the app. I'm considering overriding the back button so that, when pressed from the root B, it will pop up a dialog essentially saying "Log out? (Y/N)", thus blocking a string of back-presses from completely exiting the app.
I've noticed a sort of sensitivity regarding overriding the back button, though, and - while it makes sense to me - I want to know if this is considered a good use of the back button.
So:
Would this be considered an appropriate/conventional override of the back button?
Is there a better/more conventional way to accomplish this without overriding?
Also, so this question might be more generally useful in the future, are there any guidelines for what is acceptable/unacceptable when overriding the back button?
I would find this use acceptable; I've seen a number of apps that ask for a confirm before exit - if the user wants to exit an app, they usually will press the Home button and let Android handle the finish() if and when it's needed.
I know I've accidentally exited an app by pressing back too many times :(
Dotmister's comment about Handcent is spot on - the back button should feel natural to the user; your use seems to adhere to this, in that a user will cycle back through activities as expected for the most part. As he said though, give it a try and test it.
Coincidentally, I have a similar flow in my app, but I've included a button for the root activity.
No it is not normal to overide the back button because the user ecxpects the back button to function as a... ?? back button.
On the other side if it is really that annoying using the back button in the normal way, than a compremise? will always be better. But make sure the user still has the idea he 'controls' the device according his rules, do not make him look for yours. (dutch way of making a point, sorry).
The only way to find out is getting some people to try your application and see if it's annoying or not.

Categories

Resources