源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

android 设置wallpaper的操作方法

  • 时间:2022-09-27 05:46 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要:android 设置wallpaper的操作方法
[b]1、调用系统的Intent.ACTION_ATTACH_DATA,该Intent会唤起所有的设置壁纸程序以及设置联系人头像程序,用户可以通过ChooseActivity进行选择:[/b] 该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);
[b]2、通过WallpaperManager设置[/b] 该方法可以直接将图片置为壁纸,对于所有平台的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);
}
[b]AndroidManifest.xml中需要申明权限:[/b] <uses-permission android:name = "android.permission.SET_WALLPAPER"/> 以上这篇android 设置wallpaper的操作方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持编程素材网。
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部