是否可以使用我的应用程序以编程方式设置Live Wallpaper?
我正在开发一个应用程序,她的目的是在设备上选择一些已安装的Live墙纸,并将其设置为Live墙纸。此操作需要通过我的应用程序完成。
当我研究的时候,我发现了一些答案,这可以通过根Android设备来完成?
有没有人能帮我解决这个问题呢?
发布于 2012-12-06 20:08:01
早于Jelly Bean的Android操作系统不允许您以编程方式设置活动墙纸。目前,Jelly Bean支持在无需用户交互的情况下以编程方式更改活动墙纸
发布于 2015-09-18 02:08:35
很抱歉打断那些唱反调的人,但可以在没有用户交互的情况下以编程方式设置活动墙纸。它需要:
<uses-permission android:name="android.permission.SET_WALLPAPER_COMPONENT" />注意:对于项目#3,我使用了我自己的活动墙纸,MyWallpaperService类
只有当您的应用程序具有系统权限并且在清单中具有此权限时,才能执行此操作:
<uses-permission android:name="android.permission.SET_WALLPAPER_COMPONENT" />现在,使用反射,您可以调用WallpaperManager的隐藏方法来手动设置活动墙纸:
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());请参考源代码:
https://stackoverflow.com/questions/13683464
复制相似问题