사진을 찍어 onActivityResult()에서 가져 오려고하면 안드로이드 응용 프로그램에 문제가 있습니다. 코드가 올바르게 작동 할 수 있도록이 페이지의 정확한 코드를 복사했습니다. http://developer.android.com/training/camera/photobasics.html.사진 찍기 android
그래서 내가 사용하는 방법입니다; 내가 dispatchTakePictureIntent 전화()는 button.`
private File createImageFile() throws IOException {
// Create an image file name
String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
String imageFileName = "JPEG_" + timeStamp + "_";
File storageDir = Environment.getExternalStoragePublicDirectory(
Environment.DIRECTORY_PICTURES);
File image = File.createTempFile(
imageFileName, /* prefix */
".jpg", /* suffix */
storageDir /* directory */
);
// Save a file: path for use with ACTION_VIEW intents
mCurrentPhotoPath = "file:" + image.getAbsolutePath();
return image;
}
private void dispatchTakePictureIntent() {
Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
// Ensure that there's a camera activity to handle the intent
if (takePictureIntent.resolveActivity(getPackageManager()) != null) {
// Create the File where the photo should go
File photoFile = null;
try {
photoFile = createImageFile();
} catch (IOException ex) {
}
// Continue only if the File was successfully created
if (photoFile != null) {
takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT,
Uri.fromFile(photoFile));
startActivityForResult(takePictureIntent, 15);
}
}
}`
문제에 사용자가 클릭을하여 onActivityResult() 메서드를 호출 할 때, 나는 오른쪽 requestCode가 오른쪽의 resultCode를 얻을 수 있지만, 세 번째 매개 변수가 null입니다 때. 이미지 비트 맵 또는 경로를 가져오고 싶습니다.하지만이를 사용할 수는 없습니다. 왜 이런 일이 생길까요? 이 코드가 해당 매개 변수를 반환하지 않기 때문입니까? 이 경우 어떻게 수정해야합니까?
경로가 이미 : 미리보기 이미지를 수신 할 경우 코드에서이 줄을 제거'mCurrentPhotoPath' – njzk2
예 내가 전에 경로를 사용하려고하지만,이 일을하지 않았다, 그것은이었다 "file :"+ image.getAbsolutePaht();로 정의되어 있기 때문입니다. "file :"을 제거하고 현재 작동합니다. – Mantech