baskren / Forms9Patch

Simplify image management and text formatting in your Xamarin.Forms apps

Home Page:http://Forms9Patch.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[Bug] HTML to PDF not working on Android 10

Tims159 opened this issue · comments

Description

HTML to PDF not working on Android 10

Steps to Reproduce

  1. HTML to PDF service
  2. Android 10

Note : both ExternalStorage Persmission also added to manifest still issue persists.
Issue not present before on same nuget package 2.3.0, so might be some dependency issue.
Issue after Visual Studio update from 16.6.3 to 16.6.4.

Expected Behavior

PDF should be generated

Actual Behavior

throws
Java.IO.IOException
Message=Permission denied

Basic Information

  • Version with issue:
  • Last known good version: 2.3.0
  • IDE:
  • Platform Target Frameworks:
    • iOS:
    • Android: 10
    • UWP:
  • Android Support Library Version:
  • Nuget Packages:
  • Affected Devices: Pixel 2 XL

Screenshots

Reproduction Link

Workaround

Quck fix for now

Add android:requestLegacyExternalStorage="true" to application tag in manifest.

@Tims159

Just shared a PDF from the HTML Export page of the demo app to GMAIL on an Android 10 device without incident. Sure would be a lot easier to help if you had shared a Reproduction Link.

@Tims159

Just shared a PDF from the HTML Export page of the demo app to GMAIL on an Android 10 device without incident. Sure would be a lot easier to help if you had shared a Reproduction Link.

Issue is present only if Target Framework is Android 10(Q) in Android Options even for demo app.

its because the Android.OS.Environment.GetExternalStoragePublicDirectory(string) is depreciated.

@Tims159

I just spent 10+ minutes updating the demo project to AndroidX to be able to build for Android 10 (PIE) and, again, ran the HTML Export page in the demo project successfully. I don't doubt what you are seeing ... it's just that there are a lot of moving parts that go into a failure. 90% of the time, if a developer does not make the effort to share with me a Reproduction Link (a demo solution), there just isn't enough information to find the root cause of the issue.

Sorry, I thought its general issue, here is the demo app for issue reproduction. it only fails on device running Android 10.
forms9_issue_android10.zip

Thanks for the demo project. With it I am able to reproduce a crash. Really scratching my head as to why I couldn't get it to crash with the Forms9Patch.Demo project.

version 2.4.0.0 should address this issue. Again, I could not have fixed it without your demo project.

Thanks. And sorry for not sharing the reproduction app in the first place.

Just tried the new update. The generated pdf file name is appended with 23 digit nuber and '.' is missing before pdf. So it is not geetting associated with pdf application.
Will try on actual Pixel by Monday.

@Tims159 -

Thanks for letting me know.

  • My fault on missing the . between the filename and the suffix. Thank you for letting me know.
  • I'm backed into a corner on the 23 digit number - blame Android on this one. It's an artifact of Java.IO.File.CreateTempFile - which I didn't notice until you pointed it out to me. CreateTempFile appears to be the only approach to write a file, have it accessible to sharing, etc., AND not require user intervention (as would be the case with Android's Scoped Storage). More here if you're interested.

version 2.4.2 is now available via NuGet.org

Working :)
I was just wondering if normal create file can be used insted of temp file (temp file will append those 23 digits for uniqueness) in Cache space. Cause nowhere its written in Android docs that only temp file should be created in cache space (I might be wrong). Also path is anyway availabe to developer by using this Nuget, so the delete decision can left to developer.

Anyway just a suggestion. I'm closing the issue.