Getting error at WallpaperManager.ACTION_CHANGE_LIVE_WALLPAPER

萝らか妹 提交于 2019-12-07 04:26:46

问题


I'm creating my fist Live wallpaper by following this tutorial. But i'm getting error can not be resolved or is not a field on these two lines

WallpaperManager.ACTION_CHANGE_LIVE_WALLPAPER WallpaperManager.EXTRA_LIVE_WALLPAPER_COMPONENT

while trying to achive this

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

And compiler provides these suggessions:

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

Is any thing wrong...?


回答1:


WallpaperManager.ACTION_CHANGE_LIVE_WALLPAPER was only added in API Level 16 (4.1.2). Perhaps you have set your target SDK version to something lower than 16?

Below API level 16, you can only send the user to the overall LWP selection screen using intent action WallpaperManager.ACTION_LIVE_WALLPAPER_CHOOSER, and tell him to select your wallpaper from there. You could set up your code in the following way:

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


来源:https://stackoverflow.com/questions/14317167/getting-error-at-wallpapermanager-action-change-live-wallpaper

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!