Live Wallpaper in preview mode

The isPreview() method can be called in the onCreate(SurfaceHolder holder) method of the implemented Engine. Not in the onCreateEngine method as the prior answer because the method is not ready.


I'll write in addition to represented answers. As the preview and non-preview engine instances could exist simultaneously, you can add two static instances and one local variable of your engine inside your WallpaperService class (sample in Kotlin):

    private var engine: OpenGLEngine? = null
    private set
    //...

    companion object {
       private var engineInstance: OpenGLEngine? = null
       private var previewEngineInstance: OpenGLEngine? = null
       //...
    }

and use them in overriding functions

     override fun onCreate(surfaceHolder: SurfaceHolder?) {
        super.onCreate(surfaceHolder)
        if (isPreview) {
            previewEngineInstance = this@OpenGLEngine
            engine = previewEngineInstance
        } else {
            engineInstance = this@OpenGLEngine
            engine = engineInstance
        }
        //...
    }

    override fun onDestroy() {
        if (isPreview) {
            engine = engineInstance
            previewEngineInstance = null
        } else {
            engine = previewEngineInstance
            engineInstance = null
        }
        //...
        super.onDestroy()
    }

This way you can always get the current engine instance in your WallpaperService and call its isPreview.


Within onCreateEngine() you can use the isPreview() method.

Note that onCreateEngine() is "normally" called twice: once to create an instance for preview, and then again when you actually set the wallpaper.

Details here: http://developer.android.com/reference/android/service/wallpaper/WallpaperService.Engine.html