2014-03-28 55 views

回答

4

由於ImZaat的答案,我找到了解決辦法,ImZaat的代碼是不是爲我工作,因爲我想知道如果我的壁紙正在運行,但不是來自壁紙引擎本身,而是來自另一個活動(這是一個用於設置壁紙偏好的活動,因此它在同一個包中)。

這是我做過什麼和它的正常工作(代碼是活動中的onCreate()方法中:

WallpaperManager wpm = WallpaperManager.getInstance(this); 
    WallpaperInfo info = wpm.getWallpaperInfo(); 

    if (info != null && info.getPackageName().equals(this.getPackageName())) { 
     Log.d(TAG, "We're already running"); 
    } else { 
     Log.d(TAG, "We're not running"); 
    } 
2

你會滿足於如果你的壁紙已經設置只是檢查?

在您的實現WallpaperService#onCreateEngine(),你可以這樣做:

WallpaperManager wpm = (WallpaperManager) getSystemService(WALLPAPER_SERVICE); 
WallpaperInfo info = wpm.getWallpaperInfo(); 
if (info != null && info.getComponent().equals(new ComponentName(this, getClass()))) { 
    Log.d(TAG, "We're already running"); 
    // Still might be a preview, but the user is already running your LWP. 
} else { 
    Log.d(TAG, "We're not running, this should be a preview"); 
    // Should definitely be a preview. 
} 
+0

感謝您的答案我看到了代碼,但我認爲它是用來知道牆紙是否在運行或處於預覽模式..但可能你是對的,我會測試它,並接受你的答案,如果它的工作!謝謝 –