Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/image/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android-如果照片位于DCIM文件下,则无法在指定位置保存照片_Android_Image_File_Android Intent - Fatal编程技术网

Android-如果照片位于DCIM文件下,则无法在指定位置保存照片

Android-如果照片位于DCIM文件下,则无法在指定位置保存照片,android,image,file,android-intent,Android,Image,File,Android Intent,我现在面临一个问题: 当尝试将照片保存到我的应用程序文件下的指定位置时,如果我在DCIM文件下选择照片,我的mobileHTC D816h版本4.4.2的SD卡总是将照片存储在其他错误的位置。但是,如果它是我选择的图片文件下的照片,则裁剪的照片将保存在正确的位置 另一方面,当应用程序运行在另一台与我的相同版本HTC D626ph版本4.4.2的手机上时,一切正常 问题 如果照片来自DCIM文件,为什么我不能将其存储在指定的位置?为什么这个问题只发生在我的手机上 程序 首先,从手机图库中选择一张照

我现在面临一个问题:

当尝试将照片保存到我的应用程序文件下的指定位置时,如果我在DCIM文件下选择照片,我的mobileHTC D816h版本4.4.2的SD卡总是将照片存储在其他错误的位置。但是,如果它是我选择的图片文件下的照片,则裁剪的照片将保存在正确的位置

另一方面,当应用程序运行在另一台与我的相同版本HTC D626ph版本4.4.2的手机上时,一切正常

问题

如果照片来自DCIM文件,为什么我不能将其存储在指定的位置?为什么这个问题只发生在我的手机上

程序

首先,从手机图库中选择一张照片。第二,把照片裁剪成你想要的大小。第三,将裁剪后的照片保存到应用程序文件中的指定位置。最后,将裁剪的照片显示到ImageView

我做了很多研究,但仍然找不到解决方法或原因。希望我能在这里得到一些帮助。提前谢谢

这是我的密码:

private Uri m_uriCropPhoto = null;

private void crop(Uri uriOrig) {
    File photo = null;

    try {
        String strFilePath = getFilePath(getActivity(), "profile_crop");
        photo = createFile(strFilePath);
    } catch(Exception e) {
        Log.i("Tag","Can't create file to take picture!");
    }

    m_uriCropPhoto = Uri.fromFile(photo);

    Intent intent = new Intent("com.android.camera.action.CROP");
    intent.setDataAndType(uriOrig, "image/*");

    List<ResolveInfo> list = getActivity().getPackageManager().queryIntentActivities(intent, 0);

    if (list.size() == 0) {
        Log.i("Tag","Can't crop picture!");
    } else {
        intent.putExtra("crop", "true");
        intent.putExtra("return-data", false);
        intent.putExtra(MediaStore.EXTRA_OUTPUT, m_uriCropPhoto);
        startActivityForResult(intent,SMyCardsFragment.REQUEST_CODE_CROP_PHOTO);
    }

}

private String getFilePath(String fileName) {
    File file = getActivity().getExternalFilesDir(null);

    if (file != null) {
        return String.format(Locale.getDefault(), "%s/%s%s", file.toString(), fileName, ".jpg");
    }

    return null;
}

private File createFile(String filePath) throws Exception {
    if (TextUtils.isEmpty(filePath) == true) {
        return null;
    }

    File file = new File(filePath);
    boolean isCreated = true;

    if (file.exists() == false) {
        isCreated = file.createNewFile();
    }

    return file;
}