I am attempting to read the state of the Android battery when my repeating alarm broadcaster is called I have the following setup:
public class RepeatingAlarm extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent)
{
// Acquire the make of the device
final String PhoneModel = android.os.Build.MODEL;
final String AndroidVersion = android.os.Build.VERSION.RELEASE;
// Grab the battery information
int level = intent.getIntExtra(BatteryManager.EXTRA_LEVEL, -1);
int scale = intent.getIntExtra(BatteryManager.EXTRA_SCALE, -1);
final float batteryPct = level / (float)scale;
}
}
But I don't understand why it is returning that batteryPct = 1
. Is there something I am missing here? I added the correct permissions based on the android Google page, but that doesn't seem to have helped.