我一直在开发需要将图片设置为壁纸的应用程序。
代码:
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卡上。我哪里犯了错误?