Personally, using patached android.jar just causes headaches; using reflection is the "easy" way to access PowerProfile.java. But as @FoamyGuy and many others pointed out that this is a hidden api, so wrap it in a big attempt to catch, as it might break on a later version of Android.
Class<?> powerProfileClazz = Class.forName("com.android.internal.os.PowerProfile"); //get constructor that takes a context object Class[] argTypes = { Context.class }; Constructor constructor = powerProfileClazz .getDeclaredConstructor(argTypes); Object[] arguments = { context }; //Instantiate Object powerProInstance = constructor.newInstance(arguments); //define method Method batteryCap = powerProfileClazz.getMethod("getBatteryCapacity", null); //call method Log.d(TAG, batteryCap.invoke(powerProInstance, null).toString());
source share