我试图使用文件提供程序显示PDF文件。但是,当PDF阅读器打开时,它不包含文件的内容。该文件存储在应用程序的内部存储器中的文件夹中。FileProvider Xamarin不显示文件
清单:
<provider android:name="android.support.v4.content.FileProvider" android:authorities="com.mycom.myapp.fileprovider" android:exported="false" android:grantUriPermissions="true">
<meta-data android:name="android.support.FILE_PROVIDER_PATHS" android:resource="@xml/file_paths" />
</provider>
File_paths:
<paths xmlns:android="http://schemas.android.com/apk/res/android">
<files-path name="export" />
</paths>
pdfViewRenderer.cs:
string libraryPath = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
var path = Path.Combine(libraryPath, fileName);
string application = "application/pdf";
Java.IO.File javaFile = new Java.IO.File(fileName);//externalPath
Android.Net.Uri androidURI = FileProvider.GetUriForFile(Forms.Context.ApplicationContext, "com.mycom.myapp.fileprovider", javaFile);
Intent intent = new Intent(Intent.ActionView);
intent.SetDataAndType(androidURI, Filetype);
intent.AddFlags(ActivityFlags.GrantReadUriPermission);
intent.SetFlags(ActivityFlags.NoHistory);
intent.SetFlags(ActivityFlags.ClearWhenTaskReset);
Forms.Context.StartActivity(Intent.CreateChooser(intent, "Open PDF"));
这看起来不错,但其结果产生的.tmp将一个PDF浏览器中这种开放? – Simon
@Simon对我使用过的所有PDF查看器都很好,但是您可以使用'GetTempPath'并添加您选择的文件名.. i..e.'var savePath = Path.Combine(Path.GetTempPath(),pdfAssetName );' – SushiHangover
我昨天就和它一起工作......而且你的解决方案很好,但是仍然给我带来了同样的问题。进一步看,我发现有一个权限问题。接收应用程序正在获得权限拒绝。通过授予URI许可,这解决了它,我可以使用我的原始代码..我使用内部存储如果它的工作是错误的吗? – Simon