android - Activity 的缩略图表示

标签 android

我想要顶级 Activity 的缩略图。由于 ActivityManager.RunningTaskInfo.thumbnail 根据 documentation 始终返回 null .那么有没有其他的获取方式呢?

最佳答案

你可以试试这样的:

  1. 获取最顶层Activity View 的位图 屏幕截图 (android.R.id.content) 使用绘图缓存。
  2. 将 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/

相关文章:

android - OnCreate() 与 OnStart()

java - Android 中使用 Javamail 自动发送电子邮件

java - 无法解决 Android Studio 2.1 上的运行时错误

android - 如何将android assets css文件加载到android WebView URL

android - 从保管箱中读取文件

android - 无法在 ICS 上获取名字和姓氏的联系人

android - 解析 JSON 数组值

Android Application Record 与 pre-ICS 的兼容性

android - 使用 json post 从移动应用程序中使用 Devise 注册帐户

android - 如何在 React Native 中将按钮链接到详细信息屏幕