Canteen Card Balance - avinotec/Stundenplaner.FHE_EAH GitHub Wiki

To read the balance of the canteen card via NFC, we use the following library: https://github.com/heinrichreimer/android-canteen-balance

How to use

From the library's readme: android-canteen-balance sends broadcasts whenever a card is detected.
You could either extend AbstractCardBalanceReceiver if you want to handle the card balance in the background or AbstractCardBalanceActivity if you need the data in an activity.

We use the second option:

Option 2: Using AbstractCardBalanceReceiver:

public class CardBalanceReceiver extends AbstractCardBalanceReceiver{
    @Override
    protected void onReceiveCardBalance(Context context, CardBalance balance) {
        //TODO do something with the balance
    }
}

The register an instance of this receiver:

Context.registerReceiver(receiver, new IntentFilter(CardBalance.ACTION_CARD_BALANCE))

Do not use a receiver with intent-filter in AndroidManifest.xml as suggested in the readme of the library, because implicit broadcasts are limited since API level 24 (see Android Developer)