Arsalan
Arsalan

Reputation: 533

Getting error at WallpaperManager.ACTION_CHANGE_LIVE_WALLPAPER

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...?

Upvotes: 6

Views: 4989

Answers (1)

Thrakbad
Thrakbad

Reputation: 2738

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

Upvotes: 17

Related Questions