I am trying to open a PDF in Xamarin.Forms (Android)
How would I translate this Java to C# in the Android project (PCL) and what namespaces are used??
Intent intentUrl = new Intent(Intent.ACTION_VIEW);
intentUrl.setDataAndType(uri, "application/pdf");
intentUrl.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
mActivity.startActivity(intentUrl);
I've got this far, but how do I call the actiity in an injected class?
Uri uri = new Uri("file:///" + PathToFile(filename));
Intent intent = new Intent(Intent.ActionView);
intent.SetDataAndType(uri, "application/pdf");
intent.SetFlags(ActivityFlags.ClearTop);
Android.MainActivity. ???????
Solution
using Uri = Android.Net.Uri;
Intent intent = new Intent(Intent.ActionView);
intent.SetDataAndType(Uri.Parse("file:///" + PathToFile(filename)), "application/pdf");
intent.SetFlags(ActivityFlags.ClearTop);
Forms.Context.StartActivity(intent);
return null;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.