2014-04-24 3 views
0

저장 후 사진을 찾는 데 문제가 있습니다. 카메라에서 사진을 가져 와서 filePath를 저장하는 인 텐트를 만드는 방법은 다음과 같습니다.Android FileNotFoundException 업로드 중 사진

private void takePhoto(int position) 
{ 
    Meter meter = adapter.getItem(position); 
    Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); 
    File storageDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES); 
    File tempFile = createTempFile(meter.id, JPEG_FILE_SUFFIX, storageDir); 
    if(tempFile != null) 
    { 
     lastPhotoPath = tempFile.getAbsolutePath(); 
     Log.d(TAG, "temp picture path=" + lastPhotoPath); 
     takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, 
      Uri.fromFile(tempFile)); 
     try 
     { 
      startActivityForResult(takePictureIntent, TAKE_PHOTO_REQUEST); 
      lastPhotoPosition = position; 
     } 
     catch(ActivityNotFoundException exc) 
     { 
      Log.e(TAG, "activity to take photo not found"); 
     } 
    } 
} 

그런 다음 나중에이 이미지를 서버에 업로드하려고합니다. 여기 내가 어떻게하는지.

temp picture path=/mnt/sdcard/Pictures/19520983731349.jpg

file not found in path /mnt/sdcard/Pictures/19520983731349.jpg

그리고 예외는 방법 compose()

FileNotFoundException, FileRequestComposer compose

,536,913에 발생합니다 :

public void compose(OutputStream out) throws DataStorageException 
{ 
    Log.d("MainMenuActivity", "file not found in path " + path); 
    InputStream in = null; 
    try 
    { 
     in = new BufferedInputStream(new FileInputStream(path)); 

     // TODO: there is a better way 
     byte[] buf = new byte[8192]; 
     while(true) 
     { 
      int length = in.read(buf); 
      if(length < 0) 
       break; 
      out.write(buf, 0, length); 
     } 
    } 
    catch(FileNotFoundException exc) 
    { 
     throw new DataStorageInternalErrorException("FileNotFoundException, FileRequestComposer compose"); 
    } 
    catch(IOException exc) 
    { 
     // TODO: probably network error 
     throw new DataStorageInternalErrorException("IOException, FileRequestComposer compose"); 
    } 
    finally 
    { 
     if(in != null) 
     { 
      try 
      { 
       in.close(); 
      } 
      catch(IOException exc) 
      { 
       // FIXME 
      } 
     } 
    } 
} 

나는 그들에게 모두 완전히 동일한 저장 절약적인 filePath에서 파일 경로를 확인

내가 잘못하고있는 아이디어가 있습니까?

P. 그리고이 파일을/mnt/sdcard/Pictures mb에서 볼 수 없습니다. 그는 잃어버린거야? 아이디어를 제안하십시오.

P.P.S 매니페스트

<?xml version="1.0" encoding="utf-8"?> 
    <manifest xmlns:android="http://schemas.android.com/apk/res/android" 
    package="com.vodomer" 
    android:versionCode="1" 
    android:versionName="1.0"> 
    <uses-sdk android:minSdkVersion="7" 
       android:targetSdkVersion="19"/> 
    <uses-feature android:name="android.hardware.camera" /> 
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> 
    <uses-permission android:name="android.permission.INTERNET" /> 
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/> 
    <application android:label="@string/app_name" 
       android:name="com.vodomer.DatabaseApplication" > 
     <activity android:name="Vodomer" 
      android:label="@string/app_name" 
      android:icon="@drawable/icon" 
      android:theme="@android:style/Theme.NoTitleBar" 
      android:screenOrientation="portrait" 
      > 
      <intent-filter> 
       <action android:name="android.intent.action.MAIN" /> 
       <category android:name="android.intent.category.LAUNCHER" /> 
      </intent-filter> 
     </activity> 
     <activity android:name=".activity.AddressesListActivity" 
      android:theme="@android:style/Theme.NoTitleBar" 
      android:screenOrientation="portrait" 
      > 
     </activity> 
     <activity android:name=".activity.MainMenuActivity" 
      android:theme="@android:style/Theme.NoTitleBar" 
      android:screenOrientation="portrait" 
      > 
     </activity> 
     <activity android:name=".activity.MetersActivity" 
      android:theme="@android:style/Theme.NoTitleBar" 
      android:windowSoftInputMode="adjustPan" 
      android:screenOrientation="portrait" 
      > 
     </activity> 
     <activity android:name=".activity.PersonalAccountActivity" 
      android:theme="@android:style/Theme.NoTitleBar" 
      android:screenOrientation="portrait" 
      > 
     </activity> 
    </application> 
</manifest> 
+0

여기에 내 매니페스트 파일을 공유 할 수 있습니까? – MTahir

+0

@MTahir. 이걸 끝냈어. – Anatol

+0

''를 추가하고 코드를 테스트 해 보겠습니다. – MTahir

답변

0

문제는 당신이 파일을 생성하는 방식과 같다. 대신 createTempFile의 정규 생성자를 시도 :

File tempFile = new File(storageDir, meter.id + JPEG_FILE_SUFFIX); 

일반적으로, 당신은 또한 당신의 storageDir 폴더가 있는지 확인하고 필요한 경우 mkdirs로를 만들려고합니다.

+0

나는 지금 무슨 일이 일어나지 않았어. 하지만 그는 한 번만 내 사진을 저장했습니다. 다음번에 내가 이걸 사용하려했지만 아무 것도주지 못했습니다. – Anatol

+0

@Anatol이 이상하게 들립니다. 이것을 시도하십시오 : 수동으로 이전에 생성 된 그림을'/ mnt/sdcard/Pictures /'에서 제거하고, 위의 코드로 앱을 다시 설치하고 다시 시도하십시오. – kiruwka

0

이미지를 sdcard에 저장하기위한 경로를 추가하십시오.

final String uploadFilePath = "/mnt/sdcard/";