我将调用public final class PowerManager
带有@hide
注释的方法。
方法是:
/**
* Set the current power save mode.
*
* @return True if the set was allowed.
*
* @see #isPowerSaveMode()
*
* @hide
*/
public boolean setPowerSaveMode(boolean mode) {
try {
return mService.setPowerSaveMode(mode);
} catch (RemoteException e) {
return false;
}
}
在我的代码中,我尝试使用反射调用该方法:
Class c;
try {
c = Class.forName("android.os.PowerManager");
Method m = c.getMethod("setPowerSaveMode", new Class[]{Boolean.class});
Boolean response = (Boolean) m.invoke(true);
Log.d("test", "invoked?: " + response);
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (NoSuchMethodException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
}
但我用完了java.lang.NoSuchMethodException: setPowerSaveMode [class java.lang.Boolean]
。
我哪里错了?我怎么能调用这个方法?
先感谢您!