6

我正在按照教程创建我的拳头动态壁纸。但是我can not be resolved or is not a field在这两行上遇到了错误

WallpaperManager.ACTION_CHANGE_LIVE_WALLPAPER WallpaperManager.EXTRA_LIVE_WALLPAPER_COMPONENT

在尝试实现这一目标时

Intent intent = new Intent( WallpaperManager.ACTION_CHANGE_LIVE_WALLPAPER);
intent.putExtra(WallpaperManager.EXTRA_LIVE_WALLPAPER_COMPONENT,
            new ComponentName(this, LiveWallService.class));

编译器提供了这些建议:

WallpaperManager.ACTION_LIVE_WALLPAPER_CHOOSER
WallpaperManager.COMMAND_DROP
WallpaperManager.COMMAND_SECONDARY_TAP
WallpaperManager.COMMAND_TAP
WallpaperManager.WALLPAPER_PREVIEW_META_DATA

有什么问题吗...?

4

1 回答 1

17

WallpaperManager.ACTION_CHANGE_LIVE_WALLPAPER 仅在 API 级别 16 (4.1.2) 中添加。也许您已将目标 SDK 版本设置为低于 16?

在 API 级别 16 以下,您只能使用意图操作 WallpaperManager.ACTION_LIVE_WALLPAPER_CHOOSER 将用户发送到整个 LWP 选择屏幕,并告诉他从那里选择您的壁纸。您可以通过以下方式设置您的代码:

Intent i = new Intent();

if(Build.VERSION.SDK_INT >= 16)
{
    i.setAction(WallpaperManager.ACTION_CHANGE_LIVE_WALLPAPER);
    i.putExtra(WallpaperManager.EXTRA_LIVE_WALLPAPER_COMPONENT, new ComponentName(packageName, canonicalName));
}
else
{
    i.setAction(WallpaperManager.ACTION_LIVE_WALLPAPER_CHOOSER);
}

// send intent
于 2013-01-14T11:03:29.307 回答