我试图用反射方法改变我的小部件的亮度,但是这段代码在 setBacklightBrightness.invoke(power, new Object[]{Brightness}); 并写调用错误。请帮忙!
public static void LoadIPowerClass(Context context)
{
try{
//Load classes and objects
Object power;
Context fContext = context;
Class <?> ServiceManager = Class.forName("android.os.ServiceManager");
Class <?> Stub = Class.forName("android.os.IPowerManager$Stub");
Method getService = ServiceManager.getMethod("getService", new Class[] {String.class});
//Method asInterface = GetStub.getMethod("asInterface", new Class[] {IBinder.class});//of this class?
Method asInterface = Stub.getMethod("asInterface", new Class[] {IBinder.class}); //of this class?
IBinder iBinder = (IBinder) getService.invoke(null, new Object[] {Context.POWER_SERVICE});//
power = asInterface.invoke(null,iBinder);//or call constructor Stub?//
Method setBacklightBrightness = power.getClass().getMethod("setBacklightBrightness", new Class[]{int.class});
int Brightness = 5;
setBacklightBrightness.invoke(power, new Object[]{Brightness});//HERE Failen
Log.i(TAG, "Load internal IPower classes Ok");
}catch(InvocationTargetException e){ //HERE catch!!!!
....