Android 环信 调用相机崩掉 mikdir()

 protected void selectPicFromCamera() {
        if (!EaseCommonUtils.isSdcardExist()) {
            Toast.makeText(getActivity(), R.string.sd_card_does_not_exist, Toast.LENGTH_SHORT).show();
            return;
        }

       cameraFile = new File(Environment.getExternalStorageDirectory() + "/"  + System.currentTimeMillis() + ".jpg");

//        cameraFile = new File(PathUtil.getInstance().getImagePath(), EMClient.getInstance().getCurrentUser()
//                + System.currentTimeMillis() + ".jpg");
        //noinspection ResultOMethodCallIgnored
        Log.v("相机bug","+"+cameraFile);
        cameraFile.getParentFile().mkdirs();
        startActivityForResult(
                new Intent(MediaStore.ACTION_IMAGE_CAPTURE).putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(cameraFile)),
                REQUEST_CODE_CAMERA);
    }

解决办法:

  if (PathUtil.getInstance().getImagePath() == null) {
            PathUtil.getInstance().initDirs("", "", getActivity());
        }
        cameraFile = new File(PathUtil.getInstance().getImagePath(), EMClient.getInstance().getCurrentUser()
                + System.currentTimeMillis() + ".jpg");
        //noinspection ResultOfMethodCallIgnored
        cameraFile.getParentFile().mkdir();

网上说是初始化问题,但实在是发现不了哪里初始化不对了,最后通过该方法解决
自己判断路径是否为null,是的话则调用PathUtil的initDirs方法
 if (PathUtil.getInstance().getImagePath() == null) {
     PathUtil.getInstance().initDirs("", "", getActivity());
 }
【推广】 免费学中医,健康全家人
原文地址:https://www.cnblogs.com/zhujiabin/p/9186172.html