最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
android 设置wallpaper的操作方法
时间:2022-06-25 23:23:17 编辑:袖梨 来源:一聚教程网
1、调用系统的Intent.ACTION_ATTACH_DATA,该Intent会唤起所有的设置壁纸程序以及设置联系人头像程序,用户可以通过ChooseActivity进行选择:
该Intent是一个标准Intent,因此所有设置都会支持
Intent intent = new Intent(Intent.ACTION_ATTACH_DATA);
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
intent.putExtra("mimeType", "image/*");
Uri uri = Uri.parse(MediaStore.Images.Media
.insertImage(getActivity().getContentResolver(),
((BitmapDrawable) wallpaper).getBitmap(), null, null));
intent.setData(uri);
startActivityForResult(intent, SET_WALLPAPER);
2、通过WallpaperManager设置
该方法可以直接将图片置为壁纸,对于所有平台的Android系统都使用,但无法裁剪/调整图片。
try {
WallpaperManager wpm = (WallpaperManager) getActivity().getSystemService(
Context.WALLPAPER_SERVICE);
if (wallpaper != null) {
wpm.setBitmap(bitmap);
Log.i("xzy", "wallpaper not null");
}
} catch (IOException e) {
Log.e(TAG, "Failed to set wallpaper: " + e);
}
AndroidManifest.xml中需要申明权限:
相关文章
- 一淘电脑版官网入口 - 2026最新PC端下载 06-11
- 《迷你世界》怎么来异世界-地心传送门制作详解 06-11
- 2026年Windsurf免费替代方案:5款AI编程工具横向对比 06-11
- GitHub Copilot开发者最佳实践:团队协作中5项检查清单 06-11
- 云上智农app如何申报农民专项信贷 06-11
- 京东白拿活动入口 - 2026最新免费领商品攻略 06-11