参考了http://tech.ddvip.com/2014-05/1399380786210254.html
很详细的解说,
android4.3以后Surface下的screenshot方法移到SurfaceControl下去了
而且SurfaceControl已经@hide
只好通过反射方法来调用
Bitmap bit = null;
WindowManager mWindowManager;
DisplayMetrics mDisplayMetrics;
Display mDisplay;
mWindowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
mDisplay = mWindowManager.getDefaultDisplay();
mDisplayMetrics = new DisplayMetrics();
mDisplay.getRealMetrics(mDisplayMetrics);
float[] dims = { mDisplayMetrics.widthPixels, mDisplayMetrics.heightPixels };
Class mclass = Class.forName("android.view.SurfaceControl");
Method method = mclass.getMethod("screenshot", new Class[] {int.class, int.class});
Object obj = method.invoke(mclass, new Object[]{(int) dims[0],(int) dims[1]});
bit =(Bitmap)obj;
同样需要添加android:name="android.permission.READ_FRAME_BUFFER
以及android:sharedUserId="android.uid.system"