且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

保存拍摄的图像在SD卡上的特定文件夹

更新时间:2023-09-28 09:40:46

您可以添加的onActivityResult这code。这将您的图像存储一个名为YourFolderName文件夹中。

You can add this code in onActivityResult. This will store your image in a folder named "YourFolderName"

String extr = Environment.getExternalStorageDirectory().toString()
            + File.separator + "YourFolderName";
    File myPath = new File(extr, fileName);
    FileOutputStream fos = null;
    try {
        fos = new FileOutputStream(myPath);
        bitMap.compress(Bitmap.CompressFormat.JPEG, 100, fos);
        fos.flush();
        fos.close();
        MediaStore.Images.Media.insertImage(context.getContentResolver(),
                bitMap, myPath.getPath(), fileName);
    } catch (FileNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

还需要设置权限的清单。

also need to set permission on Manifest

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>