`
zhanglfat
  • 浏览: 89807 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

设置壁纸的三种方法

阅读更多
11111111111111111111111111111111111111111111111111
这种方法比较快 1秒之内
File file =new File ("");
    try {
InputStream fis=  new FileInputStream(file);
} catch (FileNotFoundException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}

Resources localResources = getBaseContext().getResources();
InputStream localInputStream2 = localResources
.openRawResource(getResources().getIdentifier(
"wallpaper" + imagePosition, "drawable", "com.ch"));
try {

wallpaperManager.setStream(localInputStream2);
} catch (IOException e) {
e.printStackTrace();
}



222222222222222222222222

    try { 
        wallpaperManager.setResource(getResources().getIdentifier("wallpaper" + imagePosition, "drawable", "com.ch")); 
       Toast.makeText(this, "设置成功", Toast.LENGTH_SHORT).show(); 
 
} catch (IOException e) { 
        e.printStackTrace(); 
}





33333333333333333333333333333333333333
最慢 大约要7 8 秒
WallpaperManager wallpaperManager = WallpaperManager.getInstance(this);
try {

wallpaperManager.setResource(getResources().getIdentifier("wallpaper" + imagePosition, "drawable", "com.ch"));
                Resources res = getResources();
                Bitmap bitmap=BitmapFactory.decodeResource(res, getResources().getIdentifier("wallpaper" + imagePosition, "drawable", "com.ch"));
                wallpaperManager.setBitmap(bitmap);
} catch (IOException e) {
e.printStackTrace();
}









分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics