How to stop the phone from charging via USB programmatically

Masi picture Masi · Apr 14, 2013 · Viewed 30.9k times · Source

I've tried to do as much research as possible but can't find an answer to this fairly simple question (want to figure this out before I'm going to set up the SDK and everything).I'm thinking about developing my first app and am wondering whether the BATTERY_STATUS_CHARGING from the BatteryManager contains only a get function or also a set function.

I wan't to make an app in which I can manually stop the phone from charging without unplugging it from the charger (via USB) and so am wondering whether this is actually possible.

Answer

Ajay S picture Ajay S · Apr 14, 2013

No, Its not possible on unrooted devices. It uses Settings.System with ADB_ENABLED, but ADB_ENABLED is a Secure-System-Setting which can not be changed by a application.

Yes, It can be done on rooted phone.

There is need to add an permission android.permission.WRITE_SECURE_SETTINGS.

Same type of application on Google Play : https://play.google.com/store/apps/details?id=com.jim2&hl=en