我想显示来自 URL 的图像,然后在单击按钮时将显示的图像设置为手机上的墙纸。当前它正在显示图像,但是当按下按钮保存它时没有任何反应。这是我正在使用的代码..请找出我做错了什么..提前谢谢
set = (Button) findViewById(R.id.abcd);
new DownloadImageTask((ImageView) findViewById(R.id.imageView1)).execute("http://java.sogeti.nl/JavaBlog/wp-content/uploads/2009/04/android_icon_256.png");
set.setOnClickListener(new View.OnClickListener() {
public void onClick(View arg0) {
// TODO Auto-generated method stub
Thread th = new Thread(){
public void run(){
WallpaperManager image = WallpaperManager.getInstance(getApplicationContext());
try{
image.setBitmap(photo);
}
catch(Exception ex)
{
ex.printStackTrace();
}
}
};
th.start();
}
});
}
private class DownloadImageTask extends AsyncTask<String, Void, Bitmap> {
ImageView bmImage;
public DownloadImageTask(ImageView bmImage) {
this.bmImage = bmImage;
}
protected Bitmap doInBackground(String... urls) {
String urldisplay = urls[0];
Bitmap photo = null;
try {
InputStream in = new java.net.URL(urldisplay).openStream();
babes = BitmapFactory.decodeStream(in);
} catch (Exception e) {
Log.e("Error", e.getMessage());
e.printStackTrace();
}
return photo;
}
protected void onPostExecute(Bitmap result) {
bmImage.setImageBitmap(result);
}
}