我正在开发一款Android应用程序,它使用wallpapermanager和新的调色板api从当前壁纸中提取最主要的颜色。我现在有一个问题,因为我在使用像muzei这样的动态壁纸时无法提取任何颜色。我将如何继续这样做?如果当前设置了动态壁纸,必须有类似支票的东西才会使用除wallpapermanager之外的其他东西。或者也许有可能抓住动态壁纸的屏幕截图?
谢谢!
解决方案:
//Reference to the package manager instance
PackageManager pm = getApplicationContext().getPackageManager();
/*
* Wallpaper info is not equal to null, that is if the live wallpaper
* is set, then get the drawable image from the package for the
* live wallpaper
*/
Drawable wallpaperDrawable = null;
if (WallpaperManager.getInstance(this).getWallpaperInfo() != null) {
wallpaperDrawable = WallpaperManager.getInstance(this).getWallpaperInfo().loadThumbnail(pm);
}
/*
* Else, if static wallpapers are set, then directly get the
* wallpaper image
*/
else {
wallpaperDrawable = WallpaperManager.getInstance(this).getDrawable();
}
//Drawable wallpaperDrawable = WallpaperManager.getInstance(this).getDrawable();
//Toast.makeText(this,"Wallpaper Info: " + WallpaperManager.getInstance(this).getWallpaperInfo(), Toast.LENGTH_SHORT).show();
Drawable wallpaperDrawable2 = wallpaperDrawable;