【发布时间】:2020-02-14 12:16:19
【问题描述】:
我正在使用 c# 编写一个 xmarin android 应用程序。我想打开一个位于内部存储“TESTFOLDER”的自定义文件夹中的 pdf 文件。代码在下面给出,每次它去捕获部分,它将开始活动。如何打开它?
代码
var externalPath = global::Android.OS.Environment.ExternalStorageDirectory.Path + "/TESTFOLDER";
Java.IO.File file = new Java.IO.File(externalPath, "qdummy.pdf");
if(file.Exists())
{
try
{
file.SetReadable(true);
Android.Net.Uri uri = Android.Net.Uri.FromFile(file);
Intent intent = new Intent(Intent.ActionView);
intent.SetDataAndType(uri, "application/pdf");
intent.SetFlags(ActivityFlags.ClearWhenTaskReset | ActivityFlags.NewTask);
intent.SetFlags(ActivityFlags.NoHistory);
StartActivity(intent);
}
catch (Exception ex)
{
Toast.MakeText(Application.Context, "problem", ToastLength.Long).Show();
}
}
else
{
Toast.MakeText(Application.Context, "No exx", ToastLength.Long).Show();
}
【问题讨论】:
-
希望这会有所帮助。 stackoverflow.com/questions/12194912/…
-
这能回答你的问题吗? How to open a PDF via Intent from SD card
-
你遇到了什么异常?
-
@Cheesebaron 错误是
Java.Lang.Exception: file:///storage/emulated/0/TESTFOLDER/qdummy.pdf exposed beyond app through Intent.getData() at System.Runtime.ExceptionServices.ExceptionDispatchInfo... -
这篇文章解决了同样的问题。它节省了我的一天stackoverflow.com/questions/60394507/…
标签: c# android pdf xamarin start-activity