0
从下面的代码我可以使用该图片的URL从服务器获取imageview上的图像。现在我想设置为该图像的壁纸。请提供解决方案....以便我可以在不下载图像的情况下设置壁纸。如何在android中设置从url中获取图片的壁纸
onCreate() method
{
image = (ImageView) findViewById(R.id.image);
new DownloadImage().execute(URL);
}
private class DownloadImage extends AsyncTask<String, Void, Bitmap> {
@Override
protected void onPreExecute() {
super.onPreExecute();
// Create a progressdialog
mProgressDialog = new ProgressDialog(MainActivity1.this);
mProgressDialog.setTitle("Downloading....");
mProgressDialog.setMessage("Loading...");
mProgressDialog.setIndeterminate(false);
mProgressDialog.show();
}
@Override
protected Bitmap doInBackground(String... URL) {
String imageURL = URL[0];
Bitmap bitmap = null;
try {
// Download Image from URL
InputStream input = new java.net.URL(imageURL).openStream();
// Decode Bitmap
bitmap = BitmapFactory.decodeStream(input);
} catch (Exception e) {
e.printStackTrace();
}
return bitmap;
}
@Override
protected void onPostExecute(Bitmap result) {
// Set the bitmap into ImageView
image.setImageBitmap(result);
// Close progressdialog
mProgressDialog.dismiss();
}
}
显示“网址无法解析为一个类型” – abhi
@ user3431980你需要在你的代码,你是不是刚刚返回它的位图来修改权限添加返回InputStream和这段代码在onPostExecute方法中写入 – MilapTank