티스토리 뷰

728x90

출처 : Android 7.0 Nougat OS 이미지 사진 촬영 캡처 및 자르기(1/2) - 허접샴푸로그래밍

Android7.0 이전 에서는 Uri.fromFile 함수로 파일의 URI 정보를 얻을 수 있지만, Android7.0 이후 부터는 보안상 이슈로 아래와 같이 설정하고, FileProvider.getUriForFile 함수를 이용해서 URI 정보를 얻어야 합니다.

/xml/provider_paths.xml 생성

<?xml version="1.0" encoding="utf-8"?>
<paths xmlns:android="http://schemas.android.com/apk/res/android">
    <external-path name="storage/emulated" path="."/>
</paths>

AndroidManifest.xml 내용 추가

	<provider
	   android:name="android.support.v4.content.FileProvider"
	   android:authorities="${applicationId}.provider"
	   android:exported="false"
	   android:grantUriPermissions="true">
	    <meta-data
	        android:name="android.support.FILE_PROVIDER_PATHS"
	        android:resource="@xml/provider_paths"/>
	</provider> 
	...
</application>

FileProvider.getUriForFile 사용

Uri photoUri = FileProvider.getUriForFile(
    getApplicationContext(), 
    getApplicationContext().getPackageName() + ".provider", 
    currentFile
);
댓글
300x250
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
«   2024/03   »
1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
31
글 보관함