We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Android 9.0 (API 28) throws exception when viewing the pdf file

Thread ID:

Created:

Updated:

Platform:

Replies:

144553 May 11,2019 01:57 PM UTC Oct 20,2020 11:57 AM UTC Xamarin.Forms 5
loading
Tags: PDF
Reihaneh Khaksaran
Asked On May 11, 2019 01:57 PM UTC

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



Sowmiya Loganathan [Syncfusion]
Replied On 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.  

  1. 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" ?> 
  <external-path name="external_files" path="."/> 
</paths> 
 
  1. 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> 
 
  1. 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")); 



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  


Reihaneh Khaksaran
Replied On May 14, 2019 01:08 PM UTC

Hi,

Thank you so much for your help it worked

Best regards,
Reihaneh

Sowmiya Loganathan [Syncfusion]
Replied On May 15, 2019 05:48 AM UTC

Hi Reihanes, 
 
We glad to know that the issue is resolved. 
 
Regards, 
Sowmiya L 


peterV
Replied On 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


Sowmiya Loganathan [Syncfusion]
Replied On 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 


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon