如何使用Libgdx在LiveWallpaper中使用Oreo的WallpaperColors API?

时间:2018-01-13 13:55:05

标签: java android libgdx live-wallpaper android-8.0-oreo

我正在尝试为Android创建一个livewallpaper,它使用Android 8.1的WallpaperColors API将systemUI更改为暗或亮,具体取决于livewallpaper颜色。 这是我的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+")");

    }
}

当我从创建时调用notifyColorsChanged()时,这就是logcat中显示的内容

W/WallpaperService: Can't notify system because wallpaper connection was not established.

1 个答案:

答案 0 :(得分:0)

我想让我的动态壁纸触发它们的黑暗,所以我用了它

#include <stdio.h>
#include<conio.h>

void main()
{
    FILE *fp;
    int num;

    printf("enter no of students");
    scanf("%d",&num);
    char *names = (char*) malloc(num * 100 * sizeof(char));

    printf("enter the names");
    fp = fopen("file.txt","w");

    for (int i = 0; i < num; i++)
    {
        fgets(*(names + i * 100), 100, stdin);
        fprintf(fp, "%s\n", (names + i * 100));
    }

    fclose(fp);

    fp = fopen("file.txt", "r");
    printf("names stored in *ptr");
}

如果您想即时重新计算颜色,则可能必须调用engine.notifyColorsChanged()