Sample apps are for demonstration purposes only, and should NOT be used in production environments.
This sample app demonstrates how the Push-to-Talk button on a Zebra device can be detected by Push-to-Talk applications to allow PTT functions to operate without unlocking the device.
DISCLAIMER:Zebra does not recommend using this utility for production environments. This app is an example of how to detect PTT buttons while the Android screen is locked. No Zebra support or warranty is expressed or implied.
In current versions of Android, only foreground apps can receive the events generated by the keyboard, GPIO keys, touch screen and other input devices (except HOME and BACK keys, etc.). Some of the enterprise features and apps developed for Zebra devices require certain KeyEvents to be notified even when running in the background, or when the device is in a screen-off or suspended state.
The Remote KeyEvent Service (RKES) facilitates such notifications and uses intents to alert apps to four preconfigured KeyEvents that cannot be changed. Learn more about KeyEvents.
See Zebra Keymapping Manager for more information.
Intent Action: Specifies the KeyEvent that generates the intent
Intent extras:
Intent.EXTRA_KEY_EVENT: KeyEvent object
Event objects are generated from RKES using the following data:
The intent format applies to all intents broadcast by RKES. The following section briefly describes each intent broadcast.
com.symbol.button.L1Broadcast when a KeyEvent corresponding to the key code KEYCODE_BUTTON_L1 (102) occurs.
Reserved for scanning
On devices NOT equipped with a scanner (e.g. the FR55), this key can be programmed for any purpose.
com.symbol.button.L2Broadcast when a KeyEvent corresponding to the key code KEYCODE_BUTTON_L2 (104) occurs.
Used for Push-to-Talk by default
com.symbol.button.R1Broadcast when a KeyEvent corresponding to the key code KEYCODE_BUTTON_R1 (103) occurs.
Reserved for scanning
com.symbol.button.R2Broadcast when a KeyEvent corresponding to the key code KEYCODE_BUTTON_R2 (105) occurs.
Used for headset button during Push-to-Talk sessions
The snippet below shows the broadcast receiver object.
To get the full source code, hit the " Download" button at the top of this page.
//Broadcast Receiver object
private static BroadcastReceiver keyReceivers = null;
public void createButtonReceiver() {
//Create intent filter with the required remote KeyEvent (intent) that
//needs to be received/processed by the application
final IntentFilter requestFilter = new IntentFilter();
requestFilter.addAction(“com.symbol.button.R2");
if (keyReceivers != null) {
getApplicationContext().unregisterReceiver(keyReceivers);
keyReceivers = null;
}
if (keyReceivers == null) {
//Create new broadcast receiver object and override onReceive method
keyReceivers = new BroadcastReceiver() {
@Override
public synchronized void onReceive(Context context, final Intent intent) {
try {
if (intent == null || intent.getAction() == null)
return;
KeyEvent event = intent.getParcelableExtra(Intent.EXTRA_KEY_EVENT);
if (event == null)
return;
keyAction = event.getAction();
if (event.getRepeatCount() != 0)
return;
String message = "Receiving key intent: " + intent.getAction() + " : "
+ (keyAction == KeyEvent.ACTION_DOWN ? "DOWN" : "UP");
Log.v(TAG, message);
} catch (Exception e) {
e.printStackTrace();
}
}
}
Sample apps are for demonstration purposes only, and should NOT be used in production environments.