我想要顶级 Activity 的缩略图。由于 ActivityManager.RunningTaskInfo.thumbnail
根据 documentation 始终返回 null .那么有没有其他的获取方式呢?
最佳答案
你可以试试这样的:
- 获取最顶层
Activity
View 的位图
屏幕截图 (android.R.id.content
) 使用绘图缓存。 - 将 Activity 屏幕截图缩放到所需的缩略图大小。
当然,您应该有权访问 Window
。
public Bitmap getScreenThumbnail(int width, int height) {
// grab the window view
View windowView = getWindow().getDecorView().findViewById(android.R.id.content);
// grab the topmost view
View screenView = windowView.getRootView();
// fetch view as a bitmap
screenView.setDrawingCacheEnabled(true);
Bitmap screenBitmap = Bitmap.createBitmap(screenView.getDrawingCache());
screenView.setDrawingCacheEnabled(false);
// resize to desired thumbnail size
return Bitmap.createScaledBitmap(screenBitmap, width, height, false);
}
当然,您可以跳过调整大小部分并返回完整的 screenBitmap
。
关于android - Activity 的缩略图表示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48519072/