The following code loads wallpaper in wallpaperchooser. Java,
1. Write the image name to R. array. wallpaper and save the name list of a wallpaper.
2. After the wallpaper name list is taken out, use
Stirng packagename = res. getresourcepackagename (R. array. Wallpaper), get packagename
Int id = res. getidentifiier (name, "drawable", packagename); get the id value
private void findWallpapers() { mThumbs = new ArrayList<Integer>(24); mImages = new ArrayList<Integer>(24); final Resources resources = getResources(); // Context.getPackageName() may return the "original" package name, // com.android.launcher2; Resources needs the real package name, // com.android.launcher. So we ask Resources for what it thinks the // package name should be. final String packageName = resources.getResourcePackageName(R.array.wallpapers); addWallpapers(resources, packageName, R.array.wallpapers); addWallpapers(resources, packageName, R.array.extra_wallpapers); } private void addWallpapers(Resources resources, String packageName, int list) { final String[] extras = resources.getStringArray(list); for (String extra : extras) { int res = resources.getIdentifier(extra, "drawable", packageName); if (res != 0) { final int thumbRes = resources.getIdentifier(extra + "_small", "drawable", packageName); if (thumbRes != 0) { mThumbs.add(thumbRes); mImages.add(res); // Log.d(TAG, "addWallpapers: [" + packageName + "]: " + extra + " (" + res + ")"); } } } }