在WallpaperManager.ACTION_CHANGE_LIVE_WALLPAPER上获取错误

Ars*_*lan 6 android live-wallpaper

按照本教程,我正在创建我的拳头动态壁纸.但我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));
Run Code Online (Sandbox Code Playgroud)

编译器提供了这些建议:

WallpaperManager.ACTION_LIVE_WALLPAPER_CHOOSER
WallpaperManager.COMMAND_DROP
WallpaperManager.COMMAND_SECONDARY_TAP
WallpaperManager.COMMAND_TAP
WallpaperManager.WALLPAPER_PREVIEW_META_DATA
Run Code Online (Sandbox Code Playgroud)

有什么问题吗...?

Thr*_*bad 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
Run Code Online (Sandbox Code Playgroud)