1. res/xml/file_paths.xml 생성
1
2
3
4
|
<?xml version="1.0" encoding="utf-8"?>
<paths xmlns:android="http://schemas.android.com/apk/res/android">
<external-path name="external_files" path="."/>
</paths>
|
cs |
2. AndroidManifest.xml 수정
<application> 여기사이에 넣으면 된다. </application>
1
2
3
4
5
6
7
8
9
|
<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>
|
cs |
3. intent 코드 작성(아직 잘 안됨)
**다운로드한 파일이 경로에는 있는데 갤러리앱에서 안나올때 미디어 스캔을 해줘야한다.
버전에 따라 intent.putExtra를 다르게 설정
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
MediaScanner scanner = MediaScanner.newInstance(getContext());
scanner.mediaScanning(fileToBeDownloaded.getPath()); //다운 받은 이미지파일이 갤러리에 안나올때
Intent intent = new Intent();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
Uri imgUri = FileProvider.getUriForFile(getActivity().getApplicationContext(), BuildConfig.APPLICATION_ID + ".provider", fileToBeDownloaded);
intent.putExtra(MediaStore.EXTRA_OUTPUT, imgUri);
}
else {
intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(fileToBeDownloaded));
}
intent.setDataAndType(Uri.fromFile(fileToBeDownloaded), "image/*");
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION | Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
|
cs |
참고
안드로이드 앱간 파일 공유방법 (FileProvider 대응)
Android 7.0(Nougat / API 24)에서 Intent로 URI 파일 경로 전송시 "file://" 노출되어 있으면 FileUriExposedException 오류가 발생하게 되고 앱이 종료됩니다. 앱간 파일을 공유하려면 "file://" 대신 "content:..
mixup.tistory.com
https://developer.android.com/about/versions/nougat/android-7.0-changes.html#accessibility
Android 7.0 동작 변경 사항 | Android Developers
Along with new features and capabilities, Android 7.0 includes a variety of system and API behavior changes. This document highlights some of the key changes that you should understand and account for in your apps. If you have previously published an …
developer.android.com
https://developer.android.com/reference/android/support/v4/content/FileProvider
FileProvider | Android Developers
From class android.content.ContentProvider ContentProviderResult[] applyBatch(ArrayList arg0) void attachInfo(Context arg0, ProviderInfo arg1) int bulkInsert(Uri arg0, ContentValues[] arg1) Bundle call(String arg0, String arg1, Bundle arg2) Uri canonicaliz
developer.android.com
'연구노트 > 안드로이드' 카테고리의 다른 글
안드로이드 OKHTTP (0) | 2019.06.05 |
---|---|
안드로이드 스레드에서 UI 스레드 제어하기 (0) | 2019.06.05 |
TableLayout 에서 divide by zero 문제 (0) | 2019.05.24 |
안드로이드 스튜디오 디렉토리 구조 (0) | 2019.05.23 |
Drawable - ShapeDrawable (0) | 2019.05.17 |