0

내 응용 프로그램에서 PDF 파일을 만들고 외부 저장소 인 "다운로드"디렉토리에 씁니다. 이제는 의도 한 동작으로 내 앱을 열 때 FileProvider uri를 사용하여 Google PDF 뷰어에 빈 화면이 표시되고 Adobe Acrobat에서도 파일을 열 수 없습니다. 파일을 작성한 다음 보여 주려고하는 코드는 다음과 같습니다. 로컬 알림을 보내고 알림을 통해 파일을 열려고합니다. 나는 다운로드 폴더에서 저장된 파일을 열 수 있습니다FileProvider uri를 사용하여 PDF 파일을 열면 빈 화면이 열림

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

참고 :

try { 

        File mypath=new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS),mParam1.getEmlak_id()+".pdf"); 
        document.writeTo(new FileOutputStream(mypath)); 

        document.close(); 

        NotificationManager notificationManager = (NotificationManager)getContext().getSystemService(Context.NOTIFICATION_SERVICE); 

        File file = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS),mParam1.getEmlak_id()+".pdf"); 
        Uri pdfUri = FileProvider.getUriForFile(getContext(), getContext().getApplicationContext().getPackageName() + ".com.onur.emlakdosyasi.provider", file); 
        Intent intent = new Intent(Intent.ACTION_VIEW); 
        intent.setDataAndType(pdfUri, "application/pdf"); 
        intent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY); 
        intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); 

        //use the flag FLAG_UPDATE_CURRENT to override any notification already there 
        PendingIntent contentIntent = PendingIntent.getActivity(getContext(), 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); 

        Notification notification = new Notification.Builder(getContext()) 
          .setContentTitle("title") 
          .setContentText("content") 
          .setSmallIcon(R.drawable.pdficon) 
          .setContentIntent(contentIntent) 
          .setDefaults(Notification.DEFAULT_ALL) 
          .setPriority(Notification.PRIORITY_HIGH) 
          .build(); 


        notificationManager.notify(10, notification); 

       } catch (FileNotFoundException e) { 
        e.printStackTrace(); 
       } catch (IOException e) { 
        e.printStackTrace(); 
       } 

여기 공급자 경로의 AndroidManifest.xml

<provider 
     android:name=".GenericFileProvider" 
     android:authorities="${applicationId}.com.onur.emlakdosyasi.provider" 
     android:exported="false" 
     android:grantUriPermissions="true"> 
     <meta-data 
      android:name="android.support.FILE_PROVIDER_PATHS" 
      android:resource="@xml/provider_paths"/> 
    </provider> 

내 제공자의 그리고 여기 수동으로. 난 그냥 FileProvider에 의해 제공되는 uri 통해 열 수 없습니다.

"내 보낸"필드를 변경해도 아무 것도 변경되지 않습니다.

답변

0

몇 시간 동안 모든 것을 시도하고 최후의 수단을 위해 여기에 게시했습니다. 15 분 후, 그것을 해결 ..

사람이 궁금해, 나는 내가 파일을 만든 이유는 알지도 못하는

android:name="android.support.v4.content.FileProvider" 

android:name=".GenericFileProvider" 

에서 공급자의 이름 속성을 변경 프로 바이더 클래스 자신이지만, 튜토리얼을 계속 따르는 것을 기억하고 있습니다.