不幸的是,对于静态壁纸,除了Drawable
公开的信息外,没有其他信息。您需要将最后发送到设备的服务器Bitmap
存储在您的后台服务中,然后退出运行的壁纸并手动比较位图。使用API级别12或更高时,可以使用Bitmap.sameAs
方法,但在此之前您需要手动比较像素。
public static boolean equals(Bitmap bitmap1, Bitmap bitmap2)
{
if (bitmap1 == null || bitmap2 == null)
{
return false;
}
if(Build.VERSION.SDK_INT > 11)
{
return bitmap1.sameAs(bitmap2);
}
else
{
ByteBuffer buffer1 = ByteBuffer.allocate(bitmap1.getHeight() * bitmap1.getRowBytes());
bitmap1.copyPixelsToBuffer(buffer1);
ByteBuffer buffer2 = ByteBuffer.allocate(bitmap2.getHeight() * bitmap2.getRowBytes());
bitmap2.copyPixelsToBuffer(buffer2);
return Arrays.equals(buffer1.array(), buffer2.array());
}
}