저장 후 사진을 찾는 데 문제가 있습니다. 카메라에서 사진을 가져 와서 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
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>
여기에 내 매니페스트 파일을 공유 할 수 있습니까? – MTahir
@MTahir. 이걸 끝냈어. – Anatol
' '를 추가하고 코드를 테스트 해 보겠습니다. –
MTahir