Android 活动的缩略图表示形式

Android 活动的缩略图表示形式,android,Android,我想要顶级活动的缩略图。AsActivityManager.RunningTaskInfo.thumbnail始终根据所选参数返回null。那么,还有其他方法可以获得它吗?您可以尝试以下方法: 获取最顶端的活动的视图的位图屏幕截图 (android.R.id.content)使用图形缓存 将活动屏幕截图缩放到所需的缩略图大小 当然,您应该可以访问窗口 public Bitmap getScreenThumbnail(int width, int height) { // grab th

我想要顶级活动的缩略图。As
ActivityManager.RunningTaskInfo.thumbnail
始终根据所选参数返回null。那么,还有其他方法可以获得它吗?

您可以尝试以下方法:

  • 获取最顶端的
    活动的
    视图的
    位图
    屏幕截图 (
    android.R.id.content
    )使用图形缓存
  • 将活动屏幕截图缩放到所需的缩略图大小
  • 当然,您应该可以访问
    窗口

    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);
    }
    
    当然,您可以跳过调整大小部分,而是返回完整的
    屏幕位图