Android 'set As Wallpaper' functionality

后端 未结 2 1105
广开言路
广开言路 2020-12-18 14:51

I am developing an application in which I have an image gallery and when I click on any image, it opens in full mode. But I want the set As Wallpaper functional

2条回答
  •  情话喂你
    2020-12-18 15:42

    You can launch Crop intent by start activity for result and retrieve it in result and then use wallpaper manager class. like this

    Uri imgUri=Uri.parse("android.resource://your.package.name/"+R.drawable.image); 
    Intent intent = new Intent("com.android.camera.action.CROP");  
    intent.setDataAndType(imgUri, "image/*");  
    intent.putExtra("crop", "true");  
    intent.putExtra("aspectX", 1);  
    intent.putExtra("aspectY", 1);  
    intent.putExtra("outputX", 80);  
    intent.putExtra("outputY", 80);  
    intent.putExtra("return-data", true);
    startActivityForResult(intent, REQUEST_CODE_CROP_PHOTO);
    

    and use Wallpaper manager in your onResult function

    Also keep in mind that It depends on the device whether that device is support it or not. This Intent action is not part of the internal API. Some manufacturers provide their own Gallery apps and so there is no way of knowing whether or not the user's device will recognize the Intent.

提交回复
热议问题