TargetSDKVersion이 22이므로 사용자에게 permission 요구하는 부분은 생략하였음.



File provider 사용 시 권한 관련 에러날 때

SDK 16 미만 - 권장하지 않음

List<ResolveInfo> resolvedIntentActivities = getContext().getPackageManager().queryIntentActivities(cameraInent, PackageManager.MATCH_DEFAULT_ONLY);

    for (ResolveInfo resolvedIntentInfo : resolvedIntentActivities) {

        String packageName = resolvedIntentInfo.activityInfo.packageName;

        getContext().grantUriPermission(packageName, photoURI, Intent.FLAG_GRANT_WRITE_URI_PERMISSION | Intent.FLAG_GRANT_READ_URI_PERMISSION);

    }

}


SDK 16~21

if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.LOLLIPOP) {

    takePictureIntent.setClipData(ClipData.newRawUri("", photoURI));

    takePictureIntent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION|Intent.FLAG_GRANT_READ_URI_PERMISSION);


참고 URL

http://egloos.zum.com/mightyfine/v/315645

https://github.com/ParkSangGwon/TedBottomPicker/issues/31

https://medium.com/@quiro91/sharing-files-through-intents-part-2-fixing-the-permissions-before-lollipop-ceb9bb0eec3a


+ Recent posts