5

Is it possible somehow to set Live Wallpaper programmatically using my Application?

I am working on an Application that her purpose is to choose some of the Installed Live Wallpapers on the device and to set it as a Live Wallpaper. This action need to be completed via my Application.

As I was researching I found some answers that this can be done with rooting the Android Device?

Can some one help me out how to do that exactly?

Naskov
  • 4,121
  • 5
  • 38
  • 62

2 Answers2

5

Android OS prior to Jelly Bean does not allow you to programatically set a live wallpaper. For now Jelly Bean supports changing the Live Wallpaper programtically without user interaction

Kartik Domadiya
  • 29,868
  • 19
  • 93
  • 104
  • Can you please post some example how to do that? I am listing all of the Live Wallpapers via my app and I have their package names ready, so how to stop the current LiveWallpaper and to start a new one? – Naskov Dec 06 '12 at 12:17
  • 1
    Please have a look at http://stackoverflow.com/questions/12842924/how-do-i-move-to-live-wallpaper-preview-from-app – Kartik Domadiya Dec 06 '12 at 13:00
  • 1
    that question is about Setting your own Live Wapplaper, but I am asking about changing Installed live wallpapers via my Application? Can you please answer that here? – Naskov Dec 06 '12 at 15:20
4

Sorry to break it to the nay sayers but it is possible to set a live wallpaper programmatically WITHOUT user interaction. It requires:

  1. Your app to be system-privileged
  2. <uses-permission android:name="android.permission.SET_WALLPAPER_COMPONENT" />
  3. Java reflection (super hacking code)
  4. A class reference to the desired WallpaperService (live Wallpaper)

NOTE: For item #3, I used my own live wallpaper, MyWallpaperService class

This can only be done if your app is system-privileged and has this permission in the manifest:

<uses-permission android:name="android.permission.SET_WALLPAPER_COMPONENT" />

Now, using reflection, you can call the hidden methods of WallpaperManager to manually set the live wallpaper:

WallpaperManager manager = WallpaperManager.getInstance(context);
Method method = WallpaperManager.class.getMethod("getIWallpaperManager", null);
Object objIWallpaperManager = method.invoke(manager, null);
Class[] param = new Class[1];
param[0] = ComponentName.class;
method = objIWallpaperManager.getClass().getMethod("setWallpaperComponent", param);

//get the intent of the desired wallpaper service. Note: I created my own
//custom wallpaper service. You'll need a class reference and package
//of the desired live wallpaper 
Intent intent = new Intent(WallpaperService.SERVICE_INTERFACE);
intent.setClassName(context.getPackageName(), MyWallpaperService.class.getName());

//set the live wallpaper (throws security exception if you're not system-privileged app)
method.invoke(objIWallpaperManager, intent.getComponent());

Refer to the source code:

kpninja12
  • 529
  • 6
  • 11
  • 1
    If an app got system-privileged, need a rooted device? – yelliver Sep 17 '15 at 18:10
  • It's hard to make a 3rd party application system-privileged without a rooted device because you need filesystem permission. But, you might be able to get past this. If you can run 'adb remount' on your device, you can play around with the filesystem to make your app system-privileged. If you can't use 'adb remount', you could also try this to allow temporary permission: http://stackoverflow.com/a/13366444/3992997. – kpninja12 Sep 17 '15 at 18:23
  • Brother i am really in need of the LiveWallpaper source code, can you please guide me or can provide,please. – Pir Fahim Shah Dec 18 '15 at 12:28
  • There are some great tutorials online for creating custom live wallpaper services. I followed [this tutorial](http://www.vogella.com/tutorials/AndroidLiveWallpaper/article.html) and [this tutorial](http://www.learn-android-easily.com/2013/07/android-livewallpaer-tutorial.html) – kpninja12 Dec 18 '15 at 14:54
  • this do not need a rooted device. set live wallpaper http://stackoverflow.com/a/13240311/1448357 – Gaurav Jan 31 '16 at 17:07
  • It does if you want to set the wallpaper without the user knowing about it – kpninja12 Feb 04 '16 at 21:39