Using Push-to-Talk

Enables Push-to-Talk functions on a Zebra device without unlocking it

Download

Product

EMDK For Android - 8.0

Devices

Supported on all Zebra Android devices

Overview

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.

Requirements

  • Zebra device with a PTT button running Android 6.x (Marshmallow) or later

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.


Remote Key Intents

In current versions of Android, only foreground apps are able to receive the events generated by the keyboards, 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 they are running in the background. The Remote KeyEvent Service (RKES) service facilitates such notifications and uses intents to alert apps to four preconfigured KeyEvents that cannot be changed.

Remote key intent format

Intent Action: Specifies the KeyEvent that generated the intent

Intent extras: Intent.EXTRA_KEY_EVENT: KeyEvent object

Learn more about KeyEvents

Event objects are generated from RKES using the following data:

Key Code

  • Action: 0 = key down; 1 = key up
  • Down time
  • Time of event
  • Repeat count

The intent format applies to all intents broadcast by RKES. The following section briefly describes each intent broadcast.

com.symbol.button.L1

Broadcast when a KeyEvent corresponding to the key code KEYCODE_BUTTON_L1 (102) occurs.
Reserved for scanning.

com.symbol.button.L2

Broadcast when a KeyEvent corresponding to the key code KEYCODE_BUTTON_L2 (104) occurs.
Used for Push-to-Talk

com.symbol.button.R1

Broadcast when a KeyEvent corresponding to the key code KEYCODE_BUTTON_R1 (103) occurs.
Reserved for scanning.

com.symbol.button.R2

Broadcast when a KeyEvent corresponding to the key code KEYCODE_BUTTON_R2 (105) occurs.
Used for headset button during Push-to-Talk sessions


Sample code

The snippet below shows the broadcast receiver object. Full source code is provided in the project download file.

  
  //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();
              }
           }
        }