Screenshot is not of full device UI but only of view

无人久伴 提交于 2019-12-24 16:24:18

问题


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.

来源:https://stackoverflow.com/questions/31906925/screenshot-is-not-of-full-device-ui-but-only-of-view

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!