3

How can I program the Bixby button (KeyCode: 1082) on the Samsung Galaxy S8, that it will start my application instead of the Bixby launcher? The App All in one Gestures has already this function with custom keys, but how can I do this in Android programatically?

Julian Schmuckli
  • 3,681
  • 11
  • 37
  • 64

1 Answers1

4

It seems Samsung doesn't approve of users doing this, and has apparently disabled this functionality in recent updates, at least in some places. Reports vary, but be warned that the example below might not work on every device, or at all in the near future. More details are available in the following article (off-site link to XDA Developers):

Samsung has Removed the Ability to Remap the Bixby Button on the Galaxy S8/S8+


All in one Gestures uses an AccessibilityService to accomplish this. Your app can do the same, but the user would have to explicitly enable your app as an Accessibility Service in the device Settings for it to work.

The Bixby button apparently emits simple KeyEvents with a keycode of 1082. Your AccessibilityService just needs to override the onKeyEvent() method, and check the keycode of the event passed in. For example:

public class BixbyInterceptService extends AccessibilityService {

    private static final int KEYCODE_BIXBY = 1082;

    @Override
    protected boolean onKeyEvent(KeyEvent event) {
        if (event.getKeyCode() == KEYCODE_BIXBY &&
            event.getAction() == KeyEvent.ACTION_DOWN) {

            // Do your thing here; startActivity(), Toast, Notification, etc.
            Toast.makeText(this, "Bixby button pressed", 0).show();

            // Return true to stop the event from propagating further.
            return true;
        }

        return super.onKeyEvent(event);
    }

    @Override
    public void onAccessibilityEvent(AccessibilityEvent event) {}

    @Override
    public void onInterrupt() {}
}

You'll need to properly register your AccessibilityService in the manifest for it to be eligible to be enabled as such by the user. For example, between the <application> tags:

<service
    android:name=".BixbyInterceptService"
    android:permission="android.permission.BIND_ACCESSIBILITY_SERVICE">
    <intent-filter>
        <action android:name="android.accessibilityservice.AccessibilityService" />
    </intent-filter>
    <meta-data
        android:name="android.accessibilityservice"
        android:resource="@xml/bixby_service_config" />
</service>

The resource attribute on the <meta-data> element above points to an XML file with the necessary settings for the Service. Under your project's res/ folder, create an xml/ folder if needed, and add this file there:

bixby_service_config.xml

<?xml version="1.0" encoding="utf-8"?>
<accessibility-service
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:accessibilityFlags="flagRequestFilterKeyEvents"
    android:canRequestFilterKeyEvents="true"
/>

After installation, you will need to enable your app in the Services under the Accessibility section in the device Settings.

Mike M.
  • 38,532
  • 8
  • 99
  • 95
  • where exactly bixby_service_config.xml should be created – Kriti Apr 14 '17 at 12:07
  • 1
    In `res/xml/`. Look in the folder that has the `drawable*/`, `layout*/`, etc. folders. If you don't have an `xml/` folder there already, create one, and the `bixby_service_config.xml` file goes in there. – Mike M. Apr 14 '17 at 12:13
  • @MikeM. How can I call bibxy app from intent? Thanks. My question in here https://stackoverflow.com/questions/44511645/how-to-start-bibxy-activity-using-programming – John Jun 13 '17 at 02:58
  • 1
    @user8264 Dunno. I've not had a chance to play with Bixby at all. You could try `PackageManager#getLaunchIntentForPackage()`. The package name is apparently `"com.samsung.android.app.spage"`. I have no idea if that'll work, though. – Mike M. Jun 13 '17 at 03:20