我已经通过以下方式在清单中注册了FileProvider:
<provider android:name="android.support.v4.content.FileProvider"
android:authorities="${applicationId}.provider"
android:exported="false" android:grantUriPermissions="true">
<meta-data android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/provider_paths" />
</provider>
现在,我想获取该文件的URI,以传递给另一个应用程序以打开该文件。我尝试过:
Intent viewIntent = new Intent(Intent.ActionView);
Java.IO.File document = new Java.IO.File(filePath);
Android.Net.Uri contentUri = FileProvider.GetUriForFile(
_context, Android.Support.FILE_PROVIDER_PATHS, document);
viewIntent.SetDataAndType(contentUri, GetMimeType(document));
viewIntent.SetFlags(ActivityFlags.NewTask);
viewIntent.AddFlags(ActivityFlags.GrantReadUriPermission);
Intent chooser = Intent.CreateChooser(viewIntent,
"Which program shall open the file?");
chooser.SetFlags(ActivityFlags.NewTask);
chooser.AddFlags(ActivityFlags.GrantReadUriPermission);
_context.StartActivity(chooser);
不幸的是,我似乎无法以此方式解决Android.Support.FILE_PROVIDER_PATHS
。如何获得与possibvle一样干净的URI?
答案 0 :(得分:0)
_context.PackageName + ".provider"
完成任务(_context
是Android.Content.Context
):
Intent viewIntent = new Intent(Intent.ActionView);
Java.IO.File document = new Java.IO.File(filePath);
Android.Net.Uri contentUri = FileProvider.GetUriForFile(
_context, Android.Support.FILE_PROVIDER_PATHS, document);
viewIntent.SetDataAndType(contentUri, GetMimeType(document));
viewIntent.SetFlags(ActivityFlags.NewTask);
viewIntent.AddFlags(ActivityFlags.GrantReadUriPermission);
Intent chooser = Intent.CreateChooser(viewIntent,
"Which program shall open the file?");
chooser.SetFlags(ActivityFlags.NewTask);
chooser.AddFlags(ActivityFlags.GrantReadUriPermission);
_context.StartActivity(chooser);