我正在尝试使用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);
Run Code Online (Sandbox Code Playgroud)
和onActivityResult部分:
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;
Run Code Online (Sandbox Code Playgroud)
但是,结果代码总是RESULT_CANCELED在我提供的情况下MediaStore.EXTRA_OUTPUT,即使文件不存在也是如此.