Wallpaper获取当前、修改和还原自带壁纸

添加权限:

 

<uses-permission
		android:name="android.permission.SET_WALLPAPER"></uses-permission>
 

 

private Button button1;
	private Button button2;
	private ImageView imageView1;
	private ImageView imageView2;
	private ImageView imageView3;

	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.wall_paper);

		button1 = (Button) findViewById(R.id.button1);
		button1.setOnClickListener(new OnClickListener() {

			public void onClick(View v) {
				try {
					clearWallpaper();
				} catch (IOException e) {
					e.printStackTrace();
				}
			}

		});

		imageView1 = (ImageView) findViewById(R.id.imageView1);
		imageView1.setOnClickListener(new OnClickListener() {

			public void onClick(View v) {
				Bitmap bitmap = BitmapFactory.decodeResource(getBaseContext().getResources(), R.drawable.img1);
				try {
					setWallpaper(bitmap);
				} catch (IOException e) {
					e.printStackTrace();
				}
			}

		});

		imageView2 = (ImageView) findViewById(R.id.imageView2);
		imageView2.setOnClickListener(new OnClickListener() {

			public void onClick(View v) {
				Bitmap bitmap = BitmapFactory.decodeResource(getBaseContext().getResources(), R.drawable.img2);
				try {
					setWallpaper(bitmap);
				} catch (IOException e) {
					e.printStackTrace();
				}
			}

		});
		
		button2 = (Button) findViewById(R.id.button2);
		imageView3 = (ImageView) findViewById(R.id.imageView3);
		button2.setOnClickListener(new OnClickListener() {

			public void onClick(View v) {
				imageView3.setImageDrawable(getWallpaper());
			}

		});
	}
 


Wallpaper获取当前、修改和还原自带壁纸

 

 

你可能感兴趣的:(获取)