Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I couldn't find an example either. The first thing I noticed was that the <code>EXTRA_LIVE_WALLPAPER_COMPONENT</code> doesn't require a String, but a <code>ComponentName</code>. My first cut with <code>ComponentName</code> looked like this:</p> <pre><code>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); </code></pre> <p>That didn't cut it, so I dug into the Android source code and found the following in <code>LiveWallpaperChange.java</code>:</p> <pre><code>Intent queryIntent = new Intent(WallpaperService.SERVICE_INTERFACE); queryIntent.setPackage(comp.getPackageName()); List&lt;ResolveInfo&gt; list = getPackageManager().queryIntentServices( queryIntent, PackageManager.GET_META_DATA); </code></pre> <p>A little debugging with the above chunk, and this is my final form...</p> <pre><code>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); </code></pre> <p>The key was in the second parameter to <code>ComponentName</code>.</p> <p>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:</p> <pre><code>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); } } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload