앱의 매니페스트 파일의 <application> 태그 안에 에 FileProvider 설정
<application...>
...
<provider
android:name="androidx.core.content.FileProvider"
android:authorities="패키지이름.fileprovider"
android:exported="false"
android:grantUriPermissions="true" >
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/file_paths" />
</provider>
예제
<provider
android:name="androidx.core.content.FileProvider"
android:authorities="com.example.kwanwoo.multimediatest.fileprovider"
android:exported="false"
android:grantUriPermissions="true" >
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/file_paths" />
</provider>
공유할 디렉토리에 대한 XML 태그 요소를 <path> 태그 하위에 추가
<external-files-path>
<external-files-path name="name" path="sub-directory-name" />
<files-path>
<files-path name="name" path="sub-directory-name" />
참고자료: https://developer.android.com/reference/android/support/v4/content/FileProvider.html
예제
앱 전용 외부저장소 영역의 하위의 Pictures와 Movies 디렉토리는 다른 앱과 공유 가능함을 설정
<?xml version="1.0" encoding="utf-8"?>
<paths xmlns:android="http://schemas.android.com/apk/res/android">
<external-files-path name="image_capture" path="Pictures/" />
<external-files-path name="video_capture" path="Movies/" />
</paths>
// getExternalFilesDir() + "/Pictures" should match the declaration in fileprovider.xml paths
String mPhotoFileName = "IMG"+currentDateFormat()+".jpg";
File mPhotoFile = new File(getExternalFilesDir(Environment.DIRECTORY_PICTURES), mPhotoFileName);
// wrap File object into a content provider. NOTE: authority here should match authority in manifest declaration
Uri imageUri = FileProvider.getUriForFile(this, "com.example.kwanwoo.multimediatest.fileprovider", mPhotoFile);