Android:How to access the default gallery app's wallpaper using Intents

377 views Asked by At

So, I'm making a gallery app that gets an image in the form of a Bitmap. I want the Android default gallery app to handle this. I used the Wallpaper intent but it again asked me to choose which image I wanted to set as Wallpaper. I wanna pass this step and use the selected Bitmap as wallpaper. How do I do this?

Any help would be appreciated. Thanks! PS: I don't want to use WallpaperManager as it does not have cropping option,etc. I want the default app to handle it for me (WILL IT BE FINE FOR ALL DEVICES? IF NO, THEN ALTERNATIVES?)

1

There are 1 answers

2
narancs On

This is an Intent, that helps you to load an image from your gallery:

     Intent intent = new Intent(
                        Intent.ACTION_PICK,
                        android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
                intent.setType("image/*");
                startActivityForResult(
                        Intent.createChooser(intent, getResources().getString(R.string.select_a_file)),
                        ACTION_REQUEST_GALLERY);

this should be the part of your activityOnResult. You can process the image here what you got back from your gallery. There is a bitmap at the last row, this is what the user choosed from the gallery:

 if (resultCode == RESULT_OK && requestCode == ACTION_REQUEST_GALLERY) {
            Uri selectedImageUri = data.getData();
            String[] projection = {MediaStore.MediaColumns.DATA};
            Cursor cursor = managedQuery(selectedImageUri, projection, null, null,
                    null);
            int column_index = cursor.getColumnIndexOrThrow(MediaStore.MediaColumns.DATA);
            cursor.moveToFirst();

            String selectedImagePath = cursor.getString(column_index);


            BitmapFactory.Options options = new BitmapFactory.Options();
            options.inJustDecodeBounds = true;
            BitmapFactory.decodeFile(selectedImagePath, options);
            final int REQUIRED_SIZE = 200;
            int scale = 1;
            while (options.outWidth / scale / 2 >= REQUIRED_SIZE
                    && options.outHeight / scale / 2 >= REQUIRED_SIZE)
                scale *= 2;
            options.inSampleSize = scale;
            options.inJustDecodeBounds = false;
            bitmap = BitmapFactory.decodeFile(selectedImagePath, options);

        }