设置全屏壁纸代码:
WallpaperManager instance = WallpaperManager.getInstance(mContext); WindowManager wm = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE); DisplayMetrics dm = new DisplayMetrics(); wm.getDefaultDisplay().getMetrics(dm); int desiredMinimumWidth = dm.widthPixels; int desiredMinimumHeight = dm.heightPixels; try { Thread.sleep(1000); } catch (InterruptedException e) { e.printStackTrace(); } instance.suggestDesiredDimensions(desiredMinimumWidth, desiredMinimumHeight); Bitmap bitmap = FileUtil.fitSizePic(new File(path)); instance.setBitmap(bitmap);
注意权限:
<uses-permission android:name="android.permission.SET_WALLPAPER" />
<uses-permission android:name="android.permission.SET_WALLPAPER_HINTS" />