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

查看:37
本文介绍了如何在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天全站免登陆