如何以编程方式在MIUI 10中创建文件夹?

时间:2019-07-25 05:52:40

标签: android miui

我正在做一个模块,该模块从服务器获取图像并将其保存在手机的内部存储中,图像获取部分已完成,但是当我单击某些手机中的“保存”按钮时,图像成功存储但未存储在MIUI操作系统中。 / p>

//Method for Save Image in Directory
private void saveSessionImage(int position, Bitmap bitmap, String se_photo_id_pk) {
    File file;
    String path = Environment.getExternalStorageDirectory().toString();
    File myDir = new File(path + "/FolderName");
    if (!myDir.exists()) {
        myDir.mkdirs();
    }
    file = new File(myDir, "IMG_SESSION"+se_photo_id_pk+".jpg");
    if (file.exists ()) {
        file.delete ();
    }
    try{
        OutputStream stream;
        stream = new FileOutputStream(file);
        bitmap.compress(Bitmap.CompressFormat.JPEG,100,stream);
        stream.flush();
        stream.close();
    }
    catch (IOException e) // Catch the exception
    {
        e.printStackTrace();
    }
    // Display saved image uri to TextView
    Toast.makeText(context, "Saved in Gallery!", Toast.LENGTH_SHORT).show();
    itemSessionPhotosList.remove(position);
    notifyDataSetChanged();
}

我得到了“保存在图库中!”吐司,但内部存储中没有文件夹以及图像文件

1 个答案:

答案 0 :(得分:0)

记录外部存储目录的路径并检入相应的文件夹。