Search code examples
androidlive-wallpaper

How do I detect whether my live wallpaper is running in the preview/"Set Wallpaper" activity or on the homescreen


I'd like to draw a text message only when the wallpaper is run from the live wallpaper selection app, in the preview activity. (With the "Set Wallpaper" and "Settings" buttons).

Since I'll have a free and paid version, in the free one I'd also like to make the user aware of the paid versions features, or even enable those features while previewing the wallpaper, but not when it's actually running on the homescreen to avoid annoying them.

Any ideas?

As an alternative, I might just display this information the first time the wallpapers is launched, which will always be from the preview activity.


Solution

  • 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.
    }