Screenshot is not of full device UI but only of vi

2019-08-11 18:20发布

From my app, I am trying to take a full device screenshot equivalent of the user holding their device up-volume button and power button.

I tried this approach:

rootView = view.getRootView();
Bitmap bitmap = Bitmap.createBitmap(rootView.getWidth(), rootView.getHeight(), Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
rootView.draw(canvas);

However, this is only drawing my application, and poorly at that, because if I have a menu open, or keyboard open when I take my screenshot, those areas are blacked out. :(

Someone recommended this to me:

  • if you're calling getRootView() on a view, you should end up with a screenshot of the entire app
  • taking a screenshot of the entire phone UI requires root or a running system service
  • there may be a way to make this work via the draw-overlay permission (which we now have) and creating a temporary transparent activity, but that's a fair amount of work

I can't root the phone, so I was wondering if someone could guide me to an example of code which does the "draw overlay - temp transparent activity" method to get a full device screenshot. I'm new to android, so I was having trouble finding it.

0条回答
登录 后发表回答