android 调用系统相机,预置路径,解决小米等机型uri返回为null的问题

1、相机的调用

String path= Environment.getExternalStorageDirectory().getPath() + "/"+filePath+"/";
        File file=new File(path);
        if(!file.exists()){
            boolean result=file.mkdir();
            if(!result){
     path=Environment.getExternalStorageDirectory().getPath()+"/";
            }
        };
 Intent takePictureFromCameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
        takePictureFromCameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(new File(path)));//path是指定的图片保存路径
        activity.startActivityForResult(takePictureFromCameraIntent, requestCode);

2、相机回调

 @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
        super.onActivityResult(requestCode, resultCode, intent);
        try {
            switch (requestCode) {
                case GlobalParams.CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE_NEED_CROP: // 系统相机
                    if (resultCode == Activity.RESULT_OK) {
                       //path即是系统相机保存的路径,自己处理
                    }
                    break;
               }
        }catch (Exception e){
            MobclickAgent.reportError(mContext, LogUtil.getException(e));
            e.printStackTrace();
        }
    }

你可能感兴趣的:(Android)