This demonstrates the how to write an activity that gets the current system wallpaper, - * modifies it and sets the modified bitmap as system wallpaper.
- */ -public class SetWallpaperActivity extends Activity { - /** - * Initialization of the Activity after it is first created. Must at least - * call {@link android.app.Activity#setContentView setContentView()} to - * describe what is to be displayed in the screen. - */ - @Override - protected void onCreate(Bundle savedInstanceState) { - // Be sure to call the super class. - super.onCreate(savedInstanceState); - // See assets/res/layout/wallpaper2.xml for this - // view layout definition, which is being set here as - // the content of our screen. - setContentView(R.layout.wallpaper_2); - final WallpaperManager mWallpaperManager = WallpaperManager.getInstance(this); - final BitmapDrawable mWallpaperDrawable = (BitmapDrawable) mWallpaperManager.getDrawable(); - final ImageView imageView = (ImageView) findViewById(R.id.imageview); - imageView.setDrawingCacheEnabled(true); - imageView.setImageDrawable(mWallpaperDrawable); - - Button randomize = (Button) findViewById(R.id.randomize); - randomize.setOnClickListener(new OnClickListener() { - @Override - public void onClick(View view) { - int mColor = (int) Math.floor(Math.random() * mColors.length); - mWallpaperDrawable.setColorFilter(mColors[mColor], PorterDuff.Mode.MULTIPLY); - imageView.setImageDrawable(mWallpaperDrawable); - imageView.invalidate(); - } - }); - - Button setWallpaper = (Button) findViewById(R.id.setwallpaper); - setWallpaper.setOnClickListener(new OnClickListener() { - @Override - public void onClick(View view) { - try { - mWallpaperManager.setBitmap(imageView.getDrawingCache()); - finish(); - } catch (IOException e) { - e.printStackTrace(); - } - } - }); - } - - final private int[] mColors = - {Color.BLUE, Color.GREEN, Color.RED, Color.LTGRAY, Color.MAGENTA, Color.CYAN, - Color.YELLOW, Color.WHITE}; -} -