Abrir um arquivo PDF usando o FileProvider uri abre uma tela em branco
Estou criando um arquivo PDF no meu aplicativo e gravando-o no diretório "Download" do armazenamento externo. Agora, quando o abro através do meu aplicativo com uma ação intencional.VIEW usando o FileProvider uri, o Google PDF Viewer exibe uma tela em branco, o Adobe Acrobat não pode nem mesmo abrir o arquivo. Aqui está o meu código para escrever o arquivo e depois tentar mostrá-lo. Observe que estou enviando uma notificação local e tentando abrir o arquivo através da notificação.
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();
}
Aqui está o meu provedor no 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>
E aqui estão os caminhos do provedor:
<?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/"/>
Observe que eu posso abrir o arquivo salvo da pasta Download manualmente. Eu simplesmente não consigo abri-lo através do uri fornecido pelo FileProvider.
Alterar o campo "exportado" para true não altera nada.