Question

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

Was it helpful?

Solution

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

OTHER TIPS

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.
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top