1

I am trying to create a livewallpaper for android which uses Android 8.1's WallpaperColors API to change systemUI to dark or light depending on the livewallpaper color. This is my LiveWallpaperAndroid.java

public class LiveWallpaperAndroid extends AndroidLiveWallpaperService  {
String TAG="LiveWallpaperAndroid";
@Override
public void onCreateApplication () {
    super.onCreateApplication();
    AndroidApplicationConfiguration config = new AndroidApplicationConfiguration();
    config.numSamples=0;
    config.useCompass = false;
    config.useWakelock = false;
    config.useAccelerometer = false;
    config.getTouchEventsForLiveWallpaper = true;
    ApplicationListener listener = new LiveWallpaperStarter();
    initialize(listener, config);

    if (Build.VERSION.SDK_INT >= 27) {
        linkedEngine.notifyColorsChanged();
        Log.d(TAG,"trying to notify from onCreate()");
    }
}
public class MyLiveWallpaperListener extends LiveWallpaperScreen implements AndroidWallpaperListener {
    public MyLiveWallpaperListener(Game game) {
        super(game);
    }

    @Override
    public void offsetChange (float xOffset, float yOffset, float xOffsetStep, float yOffsetStep, int xPixelOffset, int yPixelOffset) {
    }

    @Override
    public void previewStateChange (boolean isPreview) {
        Log.i("LiveWallpaper test", "previewStateChange(isPreview:"+isPreview+")");

    }
}

When I call notifyColorsChanged() from on create , this is what shows up in the logcat

W/WallpaperService: Can't notify system because wallpaper connection was not established.
Ajul Raj
  • 11
  • 3

1 Answers1

2

I wanted my live wallpaper to trigger the dark them, so I used this

public class MyEngine extends Engine

    @RequiresApi(api = Build.VERSION_CODES.O_MR1)
    @Override
    public WallpaperColors onComputeColors() {
        return new WallpaperColors(Color.valueOf(Color.BLACK), Color.valueOf(Color.BLACK), Color.valueOf(Color.BLACK));
    }

If you wanted to recalculate the color on the fly you probably have to call engine.notifyColorsChanged()

Sean Tomlins
  • 365
  • 3
  • 13