편집 기록

편집 기록
  • 프로필 정영훈님의 편집
    날짜2018.11.08

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


    이미지 분명 저장은 잘되어있습니다. 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>
    
  • 프로필 알 수 없는 사용자님의 편집
    날짜2018.09.16

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


    이미지 분명 저장은 잘되어있습니다. 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>