how to set a live wall paper by program?
I want to set one specified live wallpaper for my device, so I imitate the LiveWallpaperPreview.java which is in the LivePicker application. My code is:
public void setLiveWallpaperClick(View v) {
Intent intent = new Intent(WallpaperService.SERVICE_INTERFACE);
intent.setClassName("com.android.wallpaper", "com.android.wallpaper.galaxy.GalaxyWallpaper");
try 开发者_JAVA技巧{
mWallpaperManager.getIWallpaperManager().setWallpaperComponent(
intent.getComponent());
} catch (RemoteException e) {
e.printStackTrace();
// do nothing
} catch (RuntimeException e) {
e.printStackTrace();
}
finish();
}
And the permission in the manifest.xml is:
<uses-permission android:name="android.permission.SET_WALLPAPER_COMPONENT" />
<uses-permission android:name="android.permission.BIND_WALLPAPER" />
<uses-permission android:name="android.permission.SET_WALLPAPER" />
But It can't work in my application. Is the code right?
Thank you! I have found the root cause: The code is right. But the apk must be push to /system/app directory, it can work. If the apk is installed in /data/app, it can not work. I think there is some different permissions between /system/app and /data/app.
use following code to set custom live wallpaper :
Intent intent = new Intent(WallpaperManager.ACTION_CHANGE_LIVE_WALLPAPER); intent.putExtra(WallpaperManager.EXTRA_LIVE_WALLPAPER_COMPONENT, new ComponentName(this, MyWallpaperService.class)); startActivity(intent);
with additional permission suggested above by @Judy
here MyWallpaperService is custom wallpaper service.
精彩评论