티스토리 뷰
Android SDK level 이 7.0 이상에서 FileUri 를 사용하여 inent 로 다른 앱에 값을 전달할 경우 StricMode API 정책으로 인해 FileUriExposedException 이 발생한다.
이미 관련 블로그도 많고 구글링에도 다양한 답변을 찾을 수 있지만 정리하는 차원에서 다뤄보려 한다.
이번 포스팅에서는 FileUriExposedException 에 대해 알아보자.
Error message
Unable to start activity ComponentInfo{com.parkho.lottie/com.parkho.FileUriExposedException.MainActivity}: android.os.FileUriExposedException: file:///storage/emulated/0/text.txt exposed beyond app through ClipData.Item.getUri()
Cause
Android SDK level 이 7.0 이상일 경우 FileUri 의 노출을 금지하는 StricMode API 정책이 적용된다.
FileUril 를 포함하는 intent 가 앱을 떠나면 StricMode API 정책으로 인해 FileUriExposedException 이 발생한다.
하단은 앱 사이의 파일 공유에 대한 구글의 공식 문서다.
https://developer.android.com/about/versions/nougat/android-7.0-changes?hl=ko#sharing-files
Solution
앱 사이에 파일을 공유하려면 'content://' URI 를 보내고 이 URI 에 대해 임시 액세스 권한을 부여해야 한다.
이 권한을 가장 쉽게 부여하는 방법은 'FileProvider' 를 사용하는 방법으로 절차는 하단과 같다.
◼ res/xml/ provider_paths.xml 생성
◼ AndroidManifest.xml 에 provider 추가
◼ Uri.fromFile() -> FileProvider 대체
'Android > Troubleshooting' 카테고리의 다른 글
- Total
- Today
- Yesterday
- 무료 채굴
- 안드로이드 인텐트
- Android Service
- 앱테크 추천
- 리워드앱
- onContextItemSelected
- task
- BroadcastReceiver
- bindservice
- android task
- registerForContextMenu
- task 생성
- StringUtils
- android flag activity
- Intent
- M2E
- mPANDO
- p2e
- notifyDataSetChanged
- RoomDatabase
- StartService
- 앱테크
- android intent
- onCreateContextMenu
- 무료채굴
- 채굴앱
- 안드로이드 서비스
- 리워드 어플
- android activity flag
- WEMIX
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |