android 设置wallpaper的操作方法
1、调用系统的Intent.ACTION_ATTACH_DATA,该Intent会唤起所有的设置壁纸程序以及设置联系人头像程序,用户可以通过ChooseActivity进行选择:
该Intent是一个标准Intent,因此所有设置都会支持
Intentintent=newIntent(Intent.ACTION_ATTACH_DATA);
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
intent.putExtra("mimeType","image/*");
Uriuri=Uri.parse(MediaStore.Images.Media
.insertImage(getActivity().getContentResolver(),
((BitmapDrawable)wallpaper).getBitmap(),null,null));
intent.setData(uri);
startActivityForResult(intent,SET_WALLPAPER);
2、通过WallpaperManager设置
该方法可以直接将图片置为壁纸,对于所有平台的Android系统都使用,但无法裁剪/调整图片。
try{
WallpaperManagerwpm=(WallpaperManager)getActivity().getSystemService(
Context.WALLPAPER_SERVICE);
if(wallpaper!=null){
wpm.setBitmap(bitmap);
Log.i("xzy","wallpapernotnull");
}
}catch(IOExceptione){
Log.e(TAG,"Failedtosetwallpaper:"+e);
}
AndroidManifest.xml中需要申明权限:
以上这篇android设置wallpaper的操作方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持毛票票。