Table of Contents
Adding the SDK to you project
To use the SDK you need to add our repository to your project. Add the following line to the existing repositories
entry in your project build.gradle or settings.gradle file
1 2 3 4 |
repositories { ... maven { url "https://repo.repsy.io/mvn/handheldgroup/handheldgroup" } } |
Add the following line to the dependencies
block in you build.gradle file.
1 |
implementation 'com.handheldgroup.developertools:sidekeys:1.0.0' |
The latest version of the library is shown below
Using the SDK
The primary class for the SDK is SidekeyManager
1 |
SidekeyManager sidekeyManager = new SidekeyManager(Context context); |
Before using the SDK, you should check if the SDK is supported on the current device and OS version
1 |
boolean supported = sidekeyManager.isSupported() |
To read and modify a key, you first read it by using its id
1 2 3 4 5 6 7 8 |
// Read the current settings of the F1 key SideKeyConfig f1 = sidekeyManager.get("f1"); // The available ids differ from device to device. To get get all ids, use: String[] ids = sidekeyManager.getIds(); // or to get all keys use SideKeyConfig[] keys = sidekeyManager.getAll(); |
To modify the value of a key, use one of the methods on the SideKeyConfig
object.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
// To set a keycode provide a KeyEvent.KEYCODE_* value to key.setKeyCode(int keycode); // To set a key to trigger the scanner use key.setScanTrigger(); // To to start an app provide the package name to key.setApplication(String packageName); // To send a broadcast, provide a action to key.setBroadcast(String action); // To disable a key, call key.setDisabled(); // To restore the default setting, call key.setDefault(); |
After changing a SideKeyConfig
you need to save it by calling
1 |
sidekeyManager.set(SideKeyConfig sideKeyConfig); |
Broadcast
When you use the broadcast, register a broadcast receiver to your custom action or the default android.intent.action.KEY_EVENT
action.
In the receiver, you can get the actual KeyEvent
1 2 3 |
KeyEvent event = intent.getParcelableExtra("keyevent"); // Check event.getAction() or event.getKeyCode() depending on your use case // Please note that the broadcast is only sent for KeyEvent.ACTION_DOWN and KeyEvent.ACTION_UP |