簡體   English   中英

如何獲取有關Android中當前壁紙的信息?

[英]How can i get the information about current wallpaper in Android?

我想知道當前牆紙的文件名或文件大小。 我知道如何獲取當前牆紙的可繪制對象,如下所示:

ImageView view = new ImageView(this);
view.setImageDrawable(WallpaperManager.getInstance(this).getDrawable());

但是,我找不到獲取更多指定信息的方法。

我只想設置服務器,並使服務器每小時將一個牆紙發送到某個移動設備,幾分鍾后,我想檢查移動設備的當前牆紙是否是服務器之前發送給它的牆紙。

不幸的是,對於靜態牆紙,除了Drawable公開的信息之外,沒有其他信息。 您需要將服務器上次發送到設備的Bitmap存儲在后台服務中,然后取出正​​在運行的牆紙並手動比較位圖。 如果API級別為12或Bitmap.sameAs ,則可以使用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());
    }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM