this series aims to add varies app physical abilities with as little code lines inside the MainActivity. it is what the android studio IDEs should include as a default but they don't
so thank your lucky star I did it.

Code:

package com.yotamarker.lg200221;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.BatteryManager;

public class B8TriUtil {
    /*
    * this class gets the battery power level
    * init (in kotlin main class): val b8TriUtil = B8TriUtil();//battery level getting util //glabal var
    * step 2 : register reciever : this.registerReceiver(b8TriUtil.mBatInfoReceiver, b8TriUtil.intentFilter);
    * to get the level of the power use : b8TriUtil.b8TriLevelAsAString
    * */
    public IntentFilter intentFilter = new IntentFilter(Intent.ACTION_BATTERY_CHANGED);
    private int B8TriLevel = 0;
    public BroadcastReceiver mBatInfoReceiver = new BroadcastReceiver(){
        @Override
        public void onReceive(Context ctxt, Intent intent) {
            B8TriLevel = intent.getIntExtra(BatteryManager.EXTRA_LEVEL, 0);
            //more data :
//            int status = intent.getIntExtra(BatteryManager.EXTRA_STATUS, -1);
//            Boolean isCharging = status == BatteryManager.BATTERY_STATUS_CHARGING
//                    || status == BatteryManager.BATTERY_STATUS_FULL;
//
//            int chargePlug = intent.getIntExtra(BatteryManager.EXTRA_PLUGGED, -1);
//            Boolean usbCharge  = chargePlug == BatteryManager.BATTERY_PLUGGED_USB;
//            Boolean acCharge = chargePlug == BatteryManager.BATTERY_PLUGGED_AC;
        }
    };

    public int getB8TriLevel() {
        return B8TriLevel;
    }
    public String getB8TriLevelAsAString() {
        return B8TriLevel+" % charge";
    }
}


:hkn:

_________________
MB over and out :s6: