0

From below code I am able to get the image on imageview from server using URL of that image. Now I want to set as wallpaper of that image. Please provide solution.... so that I will be able to set wallpaper without downloading the image in my phone.

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();
        }
    }
4

1 回答 1

1
WallpaperManager wpm = WallpaperManager.getInstance(context);
InputStream ins = new URL("absolute/path/of/image").openStream();
wpm.setStream(ins);

您应该为此添加权限

<uses-permission android:name="android.permission.SET_WALLPAPER"></uses-permission>
于 2014-07-09T09:36:42.190 回答