0

我想将可绘制目录中的图像保存到手机的下载文件夹中。

我正在尝试的代码是:

Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.tradoficial);
    File sd = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS);
    String fileName = "test.jpg";
    File dest = new File(sd, fileName);
    try {
        FileOutputStream out;
        out = new FileOutputStream(dest);
        bitmap.compress(Bitmap.CompressFormat.JPEG, 100, out);
        out.flush();
        out.close();
    } catch (FileNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

但是我的手机没有任何反应。有什么不对的吗?

非常感谢!

4

1 回答 1

2

AndroidManifest.xml文件中,add <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/><manifest>标签下

于 2013-01-04T21:32:04.517 回答