当前位置: 移动技术网 > IT编程>移动开发>Android > android 设置wallpaper的操作方法

android 设置wallpaper的操作方法

2019年07月24日  | 移动技术网IT编程  | 我要评论

柏雪失踪前恐怖照片,弘创空中充值,蜡笔小新作者

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中需要申明权限:

<uses-permission android:name = "android.permission.set_wallpaper"/>

以上这篇android 设置wallpaper的操作方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持移动技术网。

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网