Android Question get "current Ampere" java code to b4a ?

dongsool

Member
Licensed User
Longtime User
B4X:
public static int getBatteryAveragePower(final Context context) {
    int voltage;
    int current = 0;

    Intent receiver =
            context.registerReceiver(null, new IntentFilter(Intent.ACTION_BATTERY_CHANGED));

    if (receiver == null) return -1;

    voltage = receiver.getIntExtra(BatteryManager.EXTRA_VOLTAGE, 0);

    BatteryManager manager = (BatteryManager) context.getSystemService(Context.BATTERY_SERVICE);
    if (manager != null) {
        current = manager.getIntProperty(BatteryManager.BATTERY_PROPERTY_CURRENT_AVERAGE);
    }

    return (voltage * current) / 1000000000;
}

I want to use the above code as an inline Java code. Help me.
 

dongsool

Member
Licensed User
Longtime User
You can get the battery level with PhoneEvents.

Calling this code multiple times will create multiple intent filters. This is not good.
Oh, thank you. I don't know if I can know the current value (?mA) through the phone event. I'll look for it.
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Upvote 0
Top