On my test phone running Android 8, a "Moto g6 play", I am not able to open the downloaded pdf file for some reasons. I've added fileProvider class, also attempted to check and request "PERMISSION_WRITE_EXTERNAL_STORAGE". I am able to see the inputstream copied to the phone internal storage [internal storage]/Android/data/com.abcd.doc.updater/files/shared/ but I am not able to open the pdf file.
Please advise. Thanks a lot.
B4X:
Sub JobDone (Job As HttpJob)
Log("JobName = " & Job.JobName & ", Success = " & Job.Success)
If Job.Success = True Then
Select Job.JobName
Case "Job1"
customPdfFilenameToSave = "abcd.pdf"
Dim OutStream As OutputStream
OutStream = File.OpenOutput(FindUserDownloadsFolder, customPdfFilenameToSave, False)
File.Copy2(Job.GetInputStream,OutStream)
OutStream.Close
OpenPDF2(File.Combine(FindUserDownloadsFolder, customPdfFilenameToSave))
End Select
Else
Log("Error: " & Job.ErrorMessage)
End If
Job.Release
End Sub
Sub OpenPDF2(FileName As String)
Dim in As Intent
in.Initialize(in.ACTION_VIEW, "")
Starter.Provider.SetFileUriAsIntentData(in, FileName)
'Type must be set after calling SetFileUriAsIntentData
in.SetType("application/pdf")
StartActivity(in)
End Sub
Sub FindUserDownloadsFolder As String
Return Starter.rp.GetSafeDirDefaultExternal("shared")
'Return Starter.Provider.SharedFolder
End Sub
Please advise. Thanks a lot.