1

I am using below code and its working properly with compileSdkVersion 22

int capacityValue=new BatteryManager().getIntProperty(BatteryManager.BATTERY_PROPERTY_CAPACITY);

but when trying to change compileSdkVersion 23 then its displaying compile time error

Error:(172, 25) error: BatteryManager() is not public in BatteryManager; cannot be accessed from outside package android

plz help me.

Android dev
  • 273
  • 2
  • 5
  • 23

1 Answers1

0

You have to register a reciever and get the info from the received intent.

Some sample code here: http://mobiledevtuts.com/android/android-sdk-get-device-battery-information/

user6547359
  • 204
  • 1
  • 9
  • Thanks for reply. I have registered broadcast and am able to get every property. but **BatteryManager.BATTERY_PROPERTY_CAPACITY** this property is added above to 21 api .and i am using below code `if(Build.VERSION.SDK_INT>=21){ int capacityValue=new BatteryManager().getIntProperty(BatteryManager.BATTERY_PROPERTY_CAPACITY); capacity.setText(String.valueOf(capacityValue)); batteryInformation.setCapacity(String.valueOf(capacityValue)); }else{ findViewById(R.id.capacity_layout).setVisibility(View.GONE); }` – Android dev Jul 07 '16 at 07:26
  • Np mate. Accept the answer for others to know it's working. – user6547359 Jul 07 '16 at 07:28