Set Live Wallpaper Programmatically on Rooted Device Android

Set Live Wallpaper Programmatically on Rooted Device Android

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

Setting live wallpaper programmatically

Alright, just so I stop getting downvotes for an outdated answer. Please see Error 454's answer below for a more robust solution which will send the user directly to the wallpaper preview screen on Jelly Bean and up devices.

========================================

Here's how to start the wallpaper chooser, from which the user can select your wallpaper. The toast is just a way to explain to the user what's going on.

Toast toast = Toast.makeText(this, "Choose '<WALLPAPER NAME>' from the list to start the Live Wallpaper.",Toast.LENGTH_LONG);
toast.show();

Intent intent = new Intent();
intent.setAction(WallpaperManager.ACTION_LIVE_WALLPAPER_CHOOSER);
startActivity(intent);

Live wallpaper that can set wallpaper to itself?

If a phone does not have the live wallpaper picker, then this phone does not support live wallpapers.

How to have live wallpaper open directly from the market?

Unlike a static wallpaper, live wallpapers cannot be set programmatically, so the user will need to select it from the live wallpaper gallery manually. So all you can do really is add some instructions to your wallpapers description on the Android Market or add an Activity that will show an instruction popup and direct you to the live wallpaper gallery.

Android : Restoring a Live Wallpaper

Setting live wallpapers are reserved for platform applications, e.g. the live wallpaper picker bundled with the device (the permission android.permission.SET_WALLPAPER_COMPONENT is defined as signatureOrSystem).

In short, you're not going to be able to do this without either rooting the device or building your own platform.

How do I move to Live Wallpaper preview from app?

I couldn't find an example either. The first thing I noticed was that the EXTRA_LIVE_WALLPAPER_COMPONENT doesn't require a String, but a ComponentName. My first cut with ComponentName looked like this:

ComponentName component = new ComponentName(getPackageName(), "LiveWallpaperService");
intent = new Intent(WallpaperManager.ACTION_CHANGE_LIVE_WALLPAPER);
intent.putExtra(WallpaperManager.EXTRA_LIVE_WALLPAPER_COMPONENT, component);
startActivityForResult(intent, REQUEST_SET_LIVE_WALLPAPER);

That didn't cut it, so I dug into the Android source code and found the following in LiveWallpaperChange.java:

Intent queryIntent = new Intent(WallpaperService.SERVICE_INTERFACE);
queryIntent.setPackage(comp.getPackageName());
List<ResolveInfo> list = getPackageManager().queryIntentServices( queryIntent, PackageManager.GET_META_DATA);

A little debugging with the above chunk, and this is my final form...

ComponentName component = new ComponentName(getPackageName(), getPackageName() + ".LiveWallpaperService");
intent = new Intent(WallpaperManager.ACTION_CHANGE_LIVE_WALLPAPER);
intent.putExtra(WallpaperManager.EXTRA_LIVE_WALLPAPER_COMPONENT, component);
startActivityForResult(intent, REQUEST_SET_LIVE_WALLPAPER);

The key was in the second parameter to ComponentName.

Technically, my final form supports a hierarchy of the new method first, followed by the old, followed by the Nook Tablet/Nook Color specific intent:

Intent intent;

// try the new Jelly Bean direct android wallpaper chooser first
try {
ComponentName component = new ComponentName(getPackageName(), getPackageName() + ".LiveWallpaperService");
intent = new Intent(WallpaperManager.ACTION_CHANGE_LIVE_WALLPAPER);
intent.putExtra(WallpaperManager.EXTRA_LIVE_WALLPAPER_COMPONENT, component);
startActivityForResult(intent, REQUEST_SET_LIVE_WALLPAPER);
}
catch (android.content.ActivityNotFoundException e3) {
// try the generic android wallpaper chooser next
try {
intent = new Intent(WallpaperManager.ACTION_LIVE_WALLPAPER_CHOOSER);
startActivityForResult(intent, REQUEST_SET_LIVE_WALLPAPER);
}
catch (android.content.ActivityNotFoundException e2) {
// that failed, let's try the nook intent
try {
intent = new Intent();
intent.setAction("com.bn.nook.CHANGE_WALLPAPER");
startActivity(intent);
}
catch (android.content.ActivityNotFoundException e) {
// everything failed, let's notify the user
showDialog(DIALOG_NO_WALLPAPER_PICKER);
}
}
}


Related Topics



Leave a reply



Submit