在Android上获取实时壁纸的图像/屏幕截图?

在Android上获取实时壁纸的图像/屏幕截图?,android,wallpaper,live-wallpaper,wallpapermanager,Android,Wallpaper,Live Wallpaper,Wallpapermanager,有没有办法使用wallpermanagerAPI获取当前实时壁纸的图像?我尝试了以下代码,但它只是返回了用于设置墙纸的应用程序的图标 PackageManager pm = getApplicationContext().getPackageManager(); // Check if user has set a live wallpaper if (WallpaperManager.getInstance(this).getWallpaperInfo() != null

有没有办法使用
wallpermanager
API获取当前实时壁纸的图像?我尝试了以下代码,但它只是返回了用于设置墙纸的应用程序的图标

  PackageManager pm = getApplicationContext().getPackageManager();

    // Check if user has set a live wallpaper
    if (WallpaperManager.getInstance(this).getWallpaperInfo() != null) {
        Drawable wallpaperDrawable = WallpaperManager.getInstance(this).getWallpaperInfo().loadThumbnail(pm);
    }
你有没有试过用它来达到这个目的。我建议查看以下代码。有关API的更多信息,请参阅

WallperManager.getInstance(this).getDrawable():仅获取静态墙纸,而不是当前的live Wallper。您可以通过WallperManager.getInstance(this).GetWallperInfo()获取live Wallper的信息。但您无法在应用程序中获取live Wallper的屏幕截图。但仍然有一个选项可用:,这只是一种可选的方式。你可以在你的应用程序中为“设置壁纸”获取当前的实时wallaper,然后你就可以获得屏幕截图了。
//You have to start the Screen Capture based on an action. 
//mWidth, mHeight depends on device screen width, height
mImageReader = ImageReader.newInstance(mWidth, mHeight, PixelFormat.RGBA_8888, 2);
mVirtualDisplay = sMediaProjection.createVirtualDisplay(SCREENCAP_NAME, mWidth, mHeight, mDensity, VIRTUAL_DISPLAY_FLAGS, mImageReader.getSurface(), null, mHandler);
mImageReader.setOnImageAvailableListener(new ImageAvailableListener(), mHandler)
startActivityForResult(mProjectionManager.createScreenCaptureIntent(), REQUEST_CODE);

//Then convert the media captured to an Image
sMediaProjection.stop();
image = mImageReader.acquireLatestImage();
Image.Plane[] planes = image.getPlanes();
ByteBuffer buffer = planes[0].getBuffer();
bitmap = Bitmap.createBitmap(mWidth, mHeight, Bitmap.Config.ARGB_8888);
bitmap.copyPixelsFromBuffer(buffer);
File file = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES), "SNAPSHOT.jpg");
fos = new FileOutputStream(file);
bitmap.compress(CompressFormat.JPEG, 100, fos);
fos.close();