Set wallpaper android (open dialog for asking)

599 views Asked by At

I want to set image as wallpaper in my android app, there is my code:

private class SetAsBackground implements View.OnClickListener {
    @Override
    public void onClick(View v) {
        new AsyncTask<Void, Void, Void>() {
            @Override
            protected Void doInBackground(Void... params) {
                Looper.prepare();
                try {
                    mShareBitmap = Glide.with(WallPaperDetails.this).load(mImageURL).asBitmap()
                            .into(-1, -1).get();
                } catch (final ExecutionException | InterruptedException e) {
                    Log.e("loading_fail", e.getMessage());
                }
                return null;
            }

            @Override
            protected void onPostExecute(Void dummy) {
                if (null != mShareBitmap) {
                    new ImageSaver(WallPaperDetails.this)
                            .setFileName("wallpaper.png")
                            .setDirectoryName("fine")
                            .save(mShareBitmap);
                    WallpaperManager myWallpaperManager = WallpaperManager
                            .getInstance(WallPaperDetails.this);
                    try {
                        Bitmap bitmap = new ImageSaver(WallPaperDetails.this)
                                .setFileName("wallpaper.png")
                                .setDirectoryName("fine").load();
                        myWallpaperManager.setBitmap(bitmap);
                        Toast.makeText(WallPaperDetails.this,
                                "Wallpaper successfully changed", Toast.LENGTH_SHORT)
                                .show();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }
            }
        }.execute();

    }
}

but I want to make like this:

please open it How can I do that ? Now I am using wallpaper manager with image saver class(I can share the code of image saver class). While searching in google, I didn't find any other answer. If you can explain how that app do that, or share some code...

1

There are 1 answers

1
Arjun On
Public void xyz(View v) {
    Intent intent = new Intent();
    intent.setType("image/*");
    intent.setAction(Intent.ACTION_GET_CONTENT);
    startActivityForResult(Intent.createChooser(intent, "Select Picture"), 0);
}