battle programmers alliance
Would you like to react to this message? Create an account in a few clicks or log in to continue.

battle programming a forum for elite programmers with extreme will power to sharpen their skills
HomeGallerySearchRegisterLog in

 Android Studio alchemy series : B8TriUtil

Go down 
Moti Barski
Moti Barski

Posts : 568
Join date : 2011-08-02

Android Studio alchemy series : B8TriUtil Empty
PostSubject: Android Studio alchemy series : B8TriUtil   Android Studio alchemy series : B8TriUtil EmptyThu Feb 25, 2021 2:11 am

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.

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(){
        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";


MB over and out emp it up
Back to top Go down
Android Studio alchemy series : B8TriUtil
Back to top 
Page 1 of 1

Permissions in this forum:You cannot reply to topics in this forum
battle programmers alliance :: battle programming alliance :: the LivinGrimoire-
Jump to: