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();
}
这种方法比较快 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();
}