Q:

setting wallpaper through code

I was trying to make an app which also had the facility to let user select wallpaper he would like to set. I have managed this by calling the Gallery Intent. Once the user selects a specific image, the data path of the image is returned to me which then i preview to the user by setting the image onto an imageview.
The problem crops up when the image size (and/or resolution) is greater than what android expects. This results in failure of my module. 
And as if this was not enough, wen the user tries to select some other wallpaper(and in my test case the "other" wallpaper was also of size >700kb) then the app crashes with the "OutOfMemoryException"...
Helppp me here guys!!!
For Gallery Intent i use:
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent, "Select Picture"),SELECT_IMAGE);

For setting the wallpaper i use: 
InputStream is = getContentResolver().openInputStream(Uri.parse(uri_returned_from_intent)); 
Bitmap bgImage = BitmapFactory.decodeStream(is);//OutOfMemory error thrown here
setWallpaper(bgImage);

So i have 2 problems to deal with:

How to crop the image before setting it as wallpaper...
Cant understand y OutOfMemoryException is thrown, coz none of my image sizes exceed even 1mb... and i guess the VM budget in case Of N1 is 24Mb if m not mistaken...

A:

You should decode with inSampleSize option to reduce memory consumption. 

Android: Strange out of memory issue while loading an image to a Bitmap object (stackoverflow)

Another option inJustDecodeBounds can help you to find correct inSampleSize value 

How to get bitmap infomation before decode an image file? (Google Groups)

