android 反射调用API中@hide的方法失败,请大神指教
杨小扬 2014-04-03 02:32:44 代码如下:
public Bitmap screenshot(int widht, int height) {
Class cl;
Bitmap shot = null;
try {
cl = Class.forName("android.view.Surface");
Object invoker = cl.newInstance();
Method screenShot = cl.getMethod("screenshot",new Class[]{int.class, int.class});
// screenShot.setAccessible(true);
Object result = screenShot.invoke(invoker, new Object[]{widht,height});
shot = (Bitmap) result;
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return shot;
}
调用方法如下:android.view.Surface
/**
* Like {@link #screenshot(int, int, int, int)} but includes all
* Surfaces in the screenshot.
*
* @hide
*/
public static Bitmap screenshot(int width, int height) {
// TODO: should take the display as a parameter
IBinder displayToken = getBuiltInDisplay(BUILT_IN_DISPLAY_ID_MAIN);
return nativeScreenshot(displayToken, width, height, 0, 0, true);
}
报错信息:
04-03 10:17:19.732: W/System.err(28374): java.lang.NoSuchMethodException: screenshot [int, int]
04-03 10:17:19.733: W/System.err(28374): at java.lang.Class.getConstructorOrMethod(Class.java:472)
04-03 10:17:19.733: W/System.err(28374): at java.lang.Class.getMethod(Class.java:864)