The method doesn't exist when I try
Set your compileSdkVersion
to 28 (or higher, if you are reading this in the distant future).
Note that this method will only be available on Android 9.0+ devices. So, unless your minSdkVersion
is 28 (or higher, for those of you reading this from your flying cars), you will need to take steps to only call this method on compatible devices:
if (Build.VERSION.SDK_INT >= 28) {
long time = mBatteryManager.computeChargeTimeRemaining();
// TODO something good with time
}
else {
// ¯\_(ツ)_/¯
}