0

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?)

Kevin Cronly
  • 1,388
  • 1
  • 13
  • 18
  • can you post some code you've tried? – Kevin Cronly Jun 24 '15 at 14:24
  • Well, tried using WallpaperManager. That's it. The intent for Android gallery didn't do much. It'd ask me to select an image from the gallery and then set it as wallpaper(After cropping, etc). I wanna skip the image selection and go straight to set as wallpaper. Shouldn't there be a way to pass the Bitmap to the default gallery app and get things done? –  Jun 24 '15 at 14:30

1 Answers1

0

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);

        }
narancs
  • 5,234
  • 4
  • 41
  • 60