6

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

Arsalan
  • 513
  • 1
  • 7
  • 22

1 Answers1

17

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
Thrakbad
  • 2,728
  • 3
  • 23
  • 31
  • can you please tell me alternate for this in less than API level 16 ? – Arsalan Jan 14 '13 at 11:10
  • Unfortunately, there is only one option below API Lvl 16 I know of, which is to tell the user to select your LWP from the list before sending him to the screen listing all installed wallpapers with WallpaperManager.ACTION_LIVE_WALLPAPER_CHOOSER. I updated my answer accordingly. – Thrakbad Jan 14 '13 at 12:17
  • 1
    I had done the above, and but still i get few errors/crash logs from 4.4,4.1 devices. why is that? – unitedartinc Nov 23 '14 at 09:58
  • @mrfarts I had the same issue, and I have a guess as to why. I looked into one of the devices that crashed, and I saw that the manufacturer had tweaked the OS a bit. I don't know how much it was tweaked, but I think not running stock android could be the problem. A full proof solution would be to use a try/catch block, like this: http://stackoverflow.com/questions/12842924/how-do-i-move-to-live-wallpaper-preview-from-app – gsgx Dec 28 '14 at 22:15
  • Testing on Android 7.0, and have the same issue. – Salman Khalid Dec 19 '18 at 18:48