I downloaded the source code from the below link and added to my project.
http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android/2.2_r1.1/com/android/internal/os/PowerProfile.java
I am getting and it can not find R file shown below.
int id = com.android.internal.R.xml.power_profile;
Also can not import
import com.android.internal.util.XmlUtils;
I basically want to measure the power consumption of Android devices.
Thanks in advance.
Personally using patached android.jar just causes headaches, using reflection is a 'simple' way of accessing PowerProfile.java. But as @FoamyGuy and countless others have noted this is hidden api so wrap it in a big try catch as it could break on 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());
Yes you can access the internal API that is com.android.internal.os.PowerProfile
just take a look at this link, and follow the step by step process.
You could use
int id = Resources.getSystem().getIdentifier("power_profile", "xml", "android");
But be aware of what FoamyGuy commented.
Easiest way to do this is to download the framework.jar of android and include that as external library in your project. After including the framework.jar in your android project you can find that resource file.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With