Android set the image i crop as wallpaper

I just crop the image to get part of it. But Android set the return image as wallpaper. What for? I am tracking Android code, and in Gallery3D application (com.cooliris) I found this:

// TODO: A temporary file is NOT necessary // The CropImage intent should be able to set the wallpaper directly // without writing to a file, which we then need to read here to write // it again as the final wallpaper, this is silly mTempFile = getFileStreamPath("temp-wallpaper"); mTempFile.getParentFile().mkdirs(); int width = getWallpaperDesiredMinimumWidth(); int height = getWallpaperDesiredMinimumHeight(); intent.putExtra("outputX", width); intent.putExtra("outputY", height); intent.putExtra("aspectX", width); intent.putExtra("aspectY", height); intent.putExtra("scale", true); intent.putExtra("noFaceDetection", true); intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(mTempFile)); intent.putExtra("outputFormat", Bitmap.CompressFormat.PNG.name()); // TODO: we should have an extra called "setWallpaper" to ask CropImage // to set the cropped image as a wallpaper directly. This means the // SetWallpaperThread should be moved out of this class to CropImage 

Please focus on the last lines, TODO. It states that the intention of the crop will complete the setting task. Well, I don’t need it at all. So, HOW TO REVERSE THE IMAGE WITHOUT INSTALLING A WALLPAPER? Thanks!

+1
source share
1 answer

Do this in your code (bearing in mind that it will not work on all phones like HTC because they use their own gallery / camera.

 File f = new File(Environment.getExternalStorageDirectory(), "/temporary_holder.png"); f.createNewFile(); Intent intent = new Intent("com.android.camera.action.CROP"); intent.setClassName("com.android.gallery", "com.android.camera.CropImage"); intent.setType("image/*"); intent.setData(ImageToSetUri); // Local URI of your image intent.putExtra("crop", true); intent.putExtra("outputX", width); // width/height of your image intent.putExtra("outputY", height); intent.putExtra("aspectX", width); intent.putExtra("aspectY", height); intent.putExtra("scale", true); intent.putExtra("noFaceDetection", true); intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(f)); intent.putExtra("outputFormat", Bitmap.CompressFormat.PNG.name()); startActivityForResult(intent, 1); 

then do this to get the image as a bitmap or nonetheless want

 public void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if (resultCode == Activity.RESULT_OK) if (data != null) { Bitmap selectedImage = BitmapFactory.decodeFile(f); } } 
+1
source

Source: https://habr.com/ru/post/1333155/


All Articles