-1
다음 코드는 디렉토리를 만들려고 시도했지만이 코드는 marshmallow까지만 작동하지만 Android 'N'에는 작동하지 않습니다.Android N에 파일 만들기
File direct = new File(Environment.getExternalStorageDirectory() + "/MyApp/Drawing");
if (!direct.exists()) {
if (direct.mkdirs()) {
Log.v(TAG, "Directory created");
}
else {
Log.v(TAG, "Directory doesn't created");
}
}
File file = new File(direct, "newfile.jpg");
Uri contentUri = FileProvider.getUriForFile(HandDrawingActivity.this, "com.example.fileprovider", file);
String fname = contentUri.getPath();
try {
FileOutputStream fos = new FileOutputStream(fname);
} catch (FileNotFoundException e){
e.printStackTrace();
}
여기이 파일에는 예외가 없습니다. 참고 : 디렉터리가 만들어지고 파일이 만들어지지 않습니다. 파일이 이미 있으면 파일을 열 수 있습니다. 도움이 될 것입니다.
7.0의 사용 권한 변경 사항을 확인하십시오. https://developer.android.com/about/versions/nougat/android-7.0-changes.html#perm –
@ThomasRoulin FileProvider를 사용하여 기존 파일을 열 수 있습니다. 내가 그것을 사용하여 새 디렉토리를 만드는 방법을 알 수 있습니까? – Gunaseelan
이 파일을 시도하십시오 direct = new File (Environment.getExternalStorageDirectory(), "Drawing"); –