Battery Event

RFID SDK for Android 2.0.2.82

Applicable Devices :Handheld Readers

Overview

This Tutorial provides a walk-through of the steps toThis Tutorial provides a walk-through of the steps to receive battery event data on the device using RFID3 API

Create The Project

  • Start by creating a new project in Android Studio. For help, see the Android Studio tutorial.
  • Refer Hello RFID to prepare basic setup to work with RFID Reader and then follow this guide

Details

BATTERY_EVENT class is used to manage the received battery event data and used by corresponding event handlers.

Please go through Event-handling guide to know how to handle the events.

Setting it up

getCause() , getLevel() , getCharging() are the methods to get battery status


//Start polling for Battery data
public static void startTimer() {
    if (scheduler == null) {
        scheduler = Executors.newScheduledThreadPool(1);
        final Runnable task = new Runnable() {
            public void run() {
                try {
                    if (reader != null)
                        reader.Config.getDeviceStatus(true, true, false);
                    else
                        stopTimer();
                } catch (InvalidUsageException e) {
                    Log.d(TAG, e.getMessage());
                } catch (OperationFailureException e) {
                    Log.d(TAG, e.getMessage());
                }
            }
        };
        taskHandle = scheduler.scheduleAtFixedRate(task, 0, 60, SECONDS);
    }
}

//Handling Battery callback event

public void eventStatusNotify(RfidStatusEvents rfidStatusEvents) {
            if( rfidStatusEvents.StatusEventData.getStatusEventType() == STATUS_EVENT_TYPE.BATTERY_EVENT ){
                    final Events.BatteryData batteryData = RfidStatusEvents.StatusEventData.BatteryData;
                    Log.d("BatteryData", batteryData.getCause());
                    Log.d("BatteryData", batteryData.getLevel());
                    Log.d("BatteryData", batteryData.getCharging());
            }
}