我正试图使用MediaStore.ACTION_IMAGE_CAPTURE意图拍摄个人资料照片。
启动意图的代码:

Intent cameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
File myPicture = new File(OfflineApp.getAppContext().getFilesDir() + "/" + getResources().getString(R.string.contact_photos_dir), getResources().getString(R.string.my_photo_file_name));
cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(myPicture));
startActivityForResult(cameraIntent, REQUEST_CODE_TAKE_PHOTO);

以及活动结果部分:
case REQUEST_CODE_TAKE_PHOTO:
    if (resultCode == RESULT_OK) {
        String path = new File(OfflineApp.getAppContext().getFilesDir() + "/" + getResources().getString(R.string.contact_photos_dir), getResources().getString(R.string.my_photo_file_name)).getAbsolutePath();
        ContactManager.getInstance().updateMyImage(path);
    }
    break;

但是,结果代码总是RESULT_CANCELED,只有在我提供MediaStore.EXTRA_OUTPUT时,即使文件不存在。

最佳答案

可以。发现了问题。
由于camera intent正在启动camera应用程序,因此它无法访问“我的应用程序”文件文件夹。通过传递外部文件夹文件并将其复制到本地文件夹,修复了此问题。
干杯。

10-07 19:33
查看更多