- Home
- Forum
- Xamarin.Forms
- Android 9.0 (API 28) throws exception when viewing the pdf file
Android 9.0 (API 28) throws exception when viewing the pdf file
Hi,
After creating a pdf file using syncfusion I try to show the file to the user using the following code snippet:
if (file.Exists())
{
Android.Net.Uri path = Android.Net.Uri.FromFile(file);
string extension = Android.Webkit.MimeTypeMap.GetFileExtensionFromUrl(Android.Net.Uri.FromFile(file).ToString());
string mimeType = Android.Webkit.MimeTypeMap.Singleton.GetMimeTypeFromExtension(extension);
Intent intent = new Intent(Intent.ActionView);
//intent.SetFlags(ActivityFlags.NewTask);
intent.SetDataAndType(path, mimeType);
Android.App.Application.Context.StartActivity(Intent.CreateChooser(intent, "Choose App"));
}
I have tested this on so many devices (with different API levels) and it's been working fine until I tested it on Android 9.0 (API level 28), on line
"Android.App.Application.Context.StartActivity(Intent.CreateChooser(intent, "Choose App"));"
it throws this exception: Android.OS.FileUriExposedException: <Timeout exceeded getting exception details>
could you please help me to resolve the issue?
P.S: I have tested this on both device and emulator, had same exception on both of them
Best regards,
Reihaneh
SIGN IN To post a reply.
5 Replies
SL
Sowmiya Loganathan
Syncfusion Team
May 13, 2019 08:47 AM UTC
Hi Reihaneh,
Greetings from Syncfusion.
Introduced a new runtime permission model for the Android SDK version 23 and above. So, we need to include the following code for enabling the Android file provider to save and view the generated PDF document in Android.
- Create a new XML file with the name of provider_paths.xml under the Android project Resources folder and add the following code in it.
Eg: Resources/xml/provider_paths.xml
|
<?xml version="1.0" encoding="UTF-8" ?>
<paths xmlns:android="http://schemas.android.com/apk/res/android">
<external-path name="external_files" path="."/>
</paths> |
- Add the following code to the AndroidManifest.xml file located under Properties/AndroidManifest.xml.
|
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="1" android:versionName="1.0" package="com.companyname. GettingStarted ">
<uses-sdk android:minSdkVersion="19" android:targetSdkVersion="27" />
<application android:label=" GettingStarted.Android">
<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>
</application>
</manifest> |
- Include the following code in the save file method of the Andoird project..
|
string extension = Android.Webkit.MimeTypeMap.GetFileExtensionFromUrl(Android.Net.Uri.FromFile(file).ToString());
string mimeType = Android.Webkit.MimeTypeMap.Singleton.GetMimeTypeFromExtension(extension);
Intent intent = new Intent(Intent.ActionView);
intent.SetFlags(ActivityFlags.ClearTop | ActivityFlags.NewTask);
Android.Net.Uri path = FileProvider.GetUriForFile(Forms.Context, Android.App.Application.Context.PackageName + ".provider", file);
intent.SetDataAndType(path, mimeType);
intent.AddFlags(ActivityFlags.GrantReadUriPermission);
Forms.Context.StartActivity(Intent.CreateChooser(intent, "Choose App")); |
Please find the helper files in the link: http://www.syncfusion.com/downloads/support/directtrac/144553/ze/Android1810726892
To know more details, kindly refer the below KB link,
Kindly try with the above solution in your end and let us know if it solves the issue.
Regards,
Sowmiya L
RK
Reihaneh Khaksaran
May 14, 2019 01:08 PM UTC
Hi,
Thank you so much for your help it worked
Best regards,
Reihaneh
SL
Sowmiya Loganathan
Syncfusion Team
May 15, 2019 05:48 AM UTC
Hi Reihanes,
We glad to know that the issue is resolved.
Regards,
Sowmiya L
PE
peterV
October 19, 2020 06:29 PM UTC
Hi, please help me
I repared project as you described but i get the error>
Severity Code Description Project File Line Suppression State
Error resource xml/provider_paths (aka com.companyname.GettingStarted:xml/provider_paths) not found. GettingStarted.Android C:\POkusy\GettingStarted\GettingStarted.Android\obj\Debug\90\android\manifest\AndroidManifest.xml 11
SL
Sowmiya Loganathan
Syncfusion Team
October 20, 2020 11:57 AM UTC
Hi Peter,
We have analyzed the reported issue. Can you please try the steps mentioned in the below KB and let us know the result,
If you still facing the issue, please provide us the below details. It will helpful for us to provide the precise solution on this,
- Complete sample
- Xamarin forms version
- Android version
Regards,
Sowmiya Loganathan
SIGN IN To post a reply.
- 5 Replies
- 3 Participants
-
RK Reihaneh Khaksaran
- May 11, 2019 01:57 PM UTC
- Oct 20, 2020 11:57 AM UTC