폰에 저장한 pdf파일을 열수가 없습니다. (안드로이드)

조회수 1137회

이미지 분명 저장은 잘되어있습니다. Abcd.pdf파일을 열고싶습니다. 이미지

근데 열면 위와같이 에러가납니다. 로그에서 Log.e("download","result : "+pdfUri.getPath()); 이부분을 찍어보면

/storage/emulated/0/Download/Abcd.pdf 잘만나옵니다..근데 왜 장치에 없다고나올까요.

File mypath=new File( Environment.getExternalStorageDirectory().getAbsolutePath() + "/Download/","Abcd.pdf");

        Log.e("download",mypath.getAbsolutePath());
        Uri pdfUri = FileProvider.getUriForFile(getApplicationContext(), getApplicationContext().getPackageName() + ".provider", mypath);



        Log.e("download",mypath.exists()+"");
        if (mypath.exists()) {
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
                Log.e("download","result : "+pdfUri.getPath());
                intent = new Intent(Intent.ACTION_VIEW);
                intent.setType("application/pdf");
                intent.putExtra(MediaStore.EXTRA_OUTPUT, pdfUri);
            }else{

            }
            intent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
            intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);


            try {
                startActivity(intent);
            }
            catch (ActivityNotFoundException e) {
                Log.e("error","error"+e);
            }
        }

res/xml/provider_path.xml

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

androidmenifest.xml

<provider
            android:authorities="${applicationId}.provider"
            android:name="android.support.v4.content.FileProvider"
            android:exported="false"
            android:grantUriPermissions="true">

            <meta-data
                android:name="android.support.FILE_PROVIDER_PATHS"
                android:resource="@xml/provider_paths"/>
        </provider>

답변을 하려면 로그인이 필요합니다.

프로그래머스 커뮤니티는 개발자들을 위한 Q&A 서비스입니다. 로그인해야 답변을 작성하실 수 있습니다.

(ಠ_ಠ)
(ಠ‿ಠ)