Android Question Open Pdf problem with intent

WebQuest

Active Member
Licensed User
Hi, I have been trying to open pdf files for hours after creation. On an old tablet the pdf files are displayed after creation using file: // but on a latest generation tablet it does not work. I followed a tutorial using FileProvider, and now the pdf viewer of drive opens with the name of the pdf file but the file is empty. some help

B4a:
Dim out As OutputStream = File.OpenOutput(File.DirRootExternal,"SmartCommerce/Fatture/"& LnomeAziendaSel.Text&"/"& LnomeAziendaSel.Text&id&".pdf", False)
    pdf.WriteToStream(out)
    out.Close
    pdf.Close
    ToastMessageShow("Fattura generata con successo",True)
   
     Dim intent As Intent
    intent.Initialize(intent.ACTION_VIEW,CreateFileProviderUri(Starter.shared,LnomeAziendaSel.Text &id&".pdf"))
    'intent.Initialize(intent.ACTION_VIEW,"file://"&File.Combine(File.DirRootExternal, "SmartCommerce/Fatture/"& LnomeAziendaSel.Text&"/"& LnomeAziendaSel.Text &id&".pdf"))
    intent.Flags = 1
    intent.SetComponent("android/com.android.internal.app.ResolverActivity")
    intent.SetType("application/pdf")
    StartActivity(intent)
 

DonManfred

Expert
Licensed User
Longtime User
You are not using filepprovider correctly.
CreateFileProviderUri(Starter.shared,LnomeAziendaSel.Text &id&".pdf"))
you are creating a shareuri for a file in the shared folder.
The pdf you are writing in 1. line is a totally another pdf...

Adapt your code, check the FileProvider tutorial again on how it should be.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…