码迷,mamicode.com
首页 > 移动开发 > 详细

android 设置wallpaper

时间:2017-08-21 00:16:45      阅读:191      评论:0      收藏:0      [点我收藏+]

标签:平台   putextra   result   ble   name   manifest   联系人   rmi   exce   

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

标签:平台   putextra   result   ble   name   manifest   联系人   rmi   exce   

原文地址:http://www.cnblogs.com/zjhangia/p/7401867.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!