2014-10-06 2 views
0

내 앱으로 사진을 찍어 폴더에 저장하려고하지만 어떤 이유로 파일이 작동하지 않습니다. 그것은 잘 만들었지 만, 그것은 단지 비어있는 파일입니다 (제가 말할 수있는 한).사진을 찍어 맞춤 폴더에 저장하면 파일이 작동하지 않습니다.

내 코드 :

private File createImageFile() throws IOException { 
    // Create an image file name 
    //String timeStamp = new SimpleDateFormat("yyyy-MM-dd").format(new Date()); 
    String imageFileName = "SCB_"; 
    String path = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES) + 
        File.separator + "/SCBimages/"; 
    File storageDir = new File(path); 
    storageDir.mkdirs(); 
    File image = File.createTempFile(
      imageFileName, /* prefix */ 
      ".jpg",   /* suffix */ 
      storageDir  /* directory */ 
    ); 

    // Save a file: path for use with ACTION_VIEW intents 
    currentPhotoPath = 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) { 
      // Error occurred while creating the File 
      System.out.println(ex.getMessage()); 
      System.out.println(Arrays.toString(ex.getStackTrace())); 
      Toast.makeText(getApplicationContext(), "Failed" + ex.getMessage(), Toast.LENGTH_SHORT).show(); 
     } 
     // Continue only if the File was successfully created 
     if (photoFile != null) { 
      takePictureIntent.putExtra("", Uri.fromFile(photoFile)); 
      startActivityForResult(takePictureIntent, REQUEST_IMAGE_CAPTURE); 
     } 
    } 
} 

호기심, 내 휴대 전화 사진을 촬영 않지만 또 다른 이름으로 더블린 코어 폴더에 저장됩니다. 문제가 무엇인지 생각하는 사람이 있습니까?

+0

당신이 onActivityResult를 작성 한 것을 보여줄 수 있어야한다을 ??? – Pankaj

답변

1

귀하의 의도와는 별도로 MediaStore.EXTRA_OUTPUT가 누락되었습니다. 내가 줄 생각 :

takePictureIntent.putExtra("", Uri.fromFile(photoFile)); 

아마

takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(photoFile)); 
+0

그리고 우리는 그것을 가지고 있습니다. 정말 고마워! – GeorgeWChubby

관련 문제