如何在Android应用程序中使用状态栏内容拍摄屏幕截图? [英] How to take a screen shot with status bar contents in android application?

查看:169
本文介绍了如何在Android应用程序中使用状态栏内容拍摄屏幕截图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要求我必须在android中截取当前窗口的截图。
这是我正在使用的代码,

I have a requirement that I have to take a screenshot of the current window in android. This is the code am using,

View rootView = getWindow().getDecorView().findViewById(android.R.id.content);
View screenView = rootView.getRootView();
screenView.setDrawingCacheEnabled(true);
Bitmap bitmap = Bitmap.createBitmap(screenView.getDrawingCache());
screenView.setDrawingCacheEnabled(false);

通过使用我可以获得应用程序屏幕截图,但状态栏内容丢失(蓝牙图标,电池状态等)。
如何以编程方式截取当前Android手机窗口的屏幕截图(包括状态栏内容)?
有可能吗?

by using this I could get the application screen shot, but the status bar contents are missing (bluetooth icon, battery status etc). How can I take a screenshot of the current Android phone window programmatically (including status bar contents)? Is it possible?

推荐答案

在Android 5.0+上,使用媒体投影API获取设备屏幕的屏幕截图。请参阅此示例应用,因为此过程涉及到某种程度。

On Android 5.0+, use the media projection APIs to take a screenshot of the device screen. See this sample app, as the process is somewhat involved.

在较旧的Android设备上,不支持设备屏幕的程序化屏幕截图。

On older Android devices, there is no support for programmatic screenshots of the device screen.

这篇关于如何在Android应用程序中使用状态栏内容拍摄屏幕截图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆