문제

I would like to know if my live wallpaper has been set or not, this is because I have a button "set wallpaper" that I would like to enable only if my wallpaper hasn't already been set.

Thaks to all

도움이 되었습니까?

해결책

Thanks to ImZaat's answer I found the solution, ImZaat's code is not working for me, as I would like to know if my wallpaper is running, but not from the wallpaper engine itself, from one other activity instead (it's an Activity used for setting some preferences about the wallpaper, so it's inside the same packege).

This is what I did and it's working fine (the code is inside the onCreate() method in the Activity:

    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");
    }

다른 팁

Would you settle for just checking if your wallpaper is already set?

In your implementation of WallpaperService#onCreateEngine() you could do:

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.
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top