android camera.My 대상 SDK를 사용하여 "appFolder"라는 폴더에 이미지를 저장하려고합니다. 내 기기가 Android에서 실행 중입니다. 누가. 그러나, "dispatchTakePictureIntent()"를 사용하여 이미지를 클릭하면. 이미지가 appFolder에 저장되지 않습니다.이 이미지는 DCIM/카메라 폴더에 저장됩니다. 왜 이런 일이 발생하고 내 사용자 폴더에이 파일을 저장합니까? 당신이 Intent
에 addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION)
를 호출하지 않았기 때문에카메라를 사용하여 캡처 한 Android 이미지가 android nougat의 지정된 사용자 폴더에 저장되지 않습니다.
<provider
android:name="android.support.v4.content.FileProvider"
android:authorities="com.abc.def"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/file_paths"></meta-data>
</provider>
Mainifest에서
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
Log.i("imageCaptutreError", ex.getMessage());
}
// Continue only if the File was successfully created
if (photoFile != null) {
Uri photoURI = FileProvider.getUriForFile(this,
"com.abc.def",
photoFile);
takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, photoURI);
startActivityForResult(takePictureIntent, REQUEST_TAKE_PHOTO);
}
}
}
private File createImageFile() throws IOException {
File folder = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + File.separator + "appFolder");
if (!folder.exists()) {
folder.mkdir();
}
File tempFile = new File(folder, "temp_image.png");
/*new File(Environment.getExternalStorageDirectory().getAbsolutePath() + File.separator + "appFolder" + File.separator + "temp_image.png");*/
mCurrentPhotoPath = tempFile.getAbsolutePath();
return tempFile;
}
제공/다 (file_paths)
<?xml version="1.0" encoding="utf-8"?>
<paths xmlns:android="http://schemas.android.com/apk/res/android">
<external-path name="my_images" path="appFolder/" />
</paths>
줄을 추가했습니다. takePictureIntent.addFlags (Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION); ....하지만 유용하지 않았다. –
@PrateekRatnaker : 그러면 카메라 앱이 'EXTRA_OUTPUT'에 관계없이 원하는 위치에 이미지를 저장하려고 결정합니다. 당신이 이것에 관해 할 수있는 일은별로 없습니다. – CommonsWare
활동 결과에 저장된 이미지의 경로를 가져와 원하는 위치에 복사 할 수 있습니까? –