6
我一直在开发需要设置图像作为壁纸的应用程序。如何以编程方式将图像设置为壁纸?
代码:
WallpaperManager m=WallpaperManager.getInstance(this);
String s=Environment.getExternalStorageDirectory().getAbsolutePath()+"/1.jpg";
File f=new File(s);
Log.e("exist", String.valueOf(f.exists()));
try {
InputStream is=new BufferedInputStream(new FileInputStream(s));
m.setBitmap(BitmapFactory.decodeFile(s));
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
Log.e("File", e.getMessage());
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
Log.e("IO", e.getMessage());
}
而且我已经添加了以下权限:
<uses-permission android:name="android.permission.SET_WALLPAPER" />
但它不工作;该文件存在于SD卡上。我在哪里犯了一个错误?
是否有抛出异常? – 2012-04-15 07:24:34