Set Live Wallpaper Programmatically on Rooted Device Android

前端 未结 2 2050
悲哀的现实
悲哀的现实 2020-11-28 15:18

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 Install

相关标签:
2条回答
  • 2020-11-28 15:53

    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:

    • LiveWallpaperActivity
    • LiveWallpaperPreview
    0 讨论(0)
  • 2020-11-28 16:00

    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

    0 讨论(0)
提交回复
热议问题