7

the Galaxy S4/S5/S6 Active and the Galaxy XCover models have this extra hardware button. In the settings the user can choose which app the button should open when it is pressed.

I'm developing an app that is specifically targeted at the Galaxy XCover 3. When the user opens the app for the first time, I want to ask the user if they want to let the hardware button open my app.

I have tried to register a broadcastreceiver on the "Camera button" event, but this doesn't work.

Does anyone know how I could achieve this result?

cjhines
  • 1,148
  • 3
  • 16
  • 32
Mark Buikema
  • 2,483
  • 30
  • 53

2 Answers2

7

I had the same problem and found a solution.

Use the code below to find the keycode.

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    super.onKeyDown(keyCode, event);
    System.out.println("keycode -->" +keyCode);
    System.out.println("Key event -->" + event );
    return false;
}

Then make a final int with the keycode.

final int ACTIVE_BUTTON = 1015;

And last write your onKeyDown event.

@Override
public boolean onKeyDown(int keyCode, KeyEvent event){
    switch(keyCode){
        case ACTIVE_BUTTON:
            //your action here
            return true;
    }
}
serv-inc
  • 35,772
  • 9
  • 166
  • 188
Maarten Lammers
  • 121
  • 2
  • 5
  • 1
    did you make some extra settings to enable this behavior? Because when I try to get the key event the `onKeyDown` listener does not react on the xcover button. Other events like volume button presses are registered correctly. – Kalle Feb 21 '17 at 09:31
  • 2
    it is working now. The problem is there are two different versions of this device, and it is only working with the newer one with Android 6 – Kalle Feb 21 '17 at 16:02
0

from Samsung:

Hardware key re-mapping Refer to this section to integrate a hardware key re-mapping configuration using the Samsung Knox SDK.

PTT key re-mapping considerations If a PTT app vendor decides to use an intent defined by Samsung, an IT Admin can either leave the intent pre-populated, or enter an intent as provided by their PTT app vendor.

List a generic intent to a PTT vendor app Vendors can also use the following intents for PTT key press and release actions:

For key press -> com.samsung.android.knox.intent.action.PTT_PRESS For key release -> com.samsung.android.knox.intent.action.PTT_RELEASE The following optional timestamp can also be considered:

Extra -> com.samsung.android.knox.intent.extra.EVENT_TIMESTAMP (with type long which will hold the Epoch timestamp of the event) Secure PTT intents The Samsung Knox team recommends registering an intent in manifest statically so KSP can wake the app if in a stopped state. Consider the following:

<receiver

android:name=".PTTKeyReceiver"

android:permission="com.samsung.android.knox.permission.KNOX_CUSTOM_SETTING"

android:exported="true" >

Optional Security: To ensure a PTT vendor app is listening to intent actions only from KSP, an app can add the above permission in the receiver, which is platform signature protected.

reference:

https://docs.samsungknox.com/admin/knox-service-plugin/Hardware_key_re-mapping.htm

droideckar
  • 1,077
  • 10
  • 20