0

私のアプリケーションでPDFファイルを作成し、外部ストレージの "Download"ディレクトリに書き込みます。さて、FileProvider uriを使って、私のアプリを介してアプリを開いてみると、Google PDF Viewerには空白の画面が表示され、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を介して開くことができません。

"exported"フィールドをtrueに変更しても何も変更されません。

答えて

0

何時間も試してみましたが、最後の手段としてここに投稿しました。 15分後、それを解決した。..

誰もが不思議について、私は、ファイルを作成した理由を私も知りません

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

android:name=".GenericFileProvider" 

からプロバイダのname属性を変更しましたプロバイダのクラスは自分自身ですが、私はそれのためのチュートリアルを覚えています。

関連する問題