I think that GetFileUri requires the full file path but you are passing only the file name.
Try:
Dim FullFilePath As String
FullFilePath = File.Combine([Dir of your files here], title)
Dim tURI As String = Provider.GetFileUri(FullFilePath)
Also:
Dim Ext As String
Ext = filePath.SubString(FullFilePath.LastIndexOf(".") + 1).ToLowerCase
Select Ext
Case "pdf"
in.SetType("application/pdf")
Case "" 'add other file extensions here.
End Select
StartActivity(in)
EDIT: slightly modified.
So here's my current code for selecting and opening a file (pdf, doc, docx) from a ListView.
I set the code with your hints into my code...
Private Sub lvSongs_ItemClick(Position As Int, Value As Object)
IME.HideKeyboard
Dim lvd As lvData 'Type defined in Globals Type lvData(Ttl As String,Art As String,id As String)
lvd.Initialize
lvd = Value
If Value <> "" Then
Dim title As String = lvd.Ttl
Dim FullFilePath As String
Dim cfp As String = Starter.ContentFolderPath 'Set after the importing of the filenames from the selected folder. Done on another Activity.
FullFilePath = File.Combine(cfp,title)
Log(FullFilePath) ' Produces: content:/com.android.externalstorage.documents/tree/primary%3ACharts%2FGospel%20Jam/A Daisy A Day.pdf
rp.GetAllSafeDirsExternal(cfp) 'thought this might help with setting the permission to External folders
Dim in As Intent
in.Initialize(in.ACTION_VIEW,FullFilePath)
Dim ext As String = GetExt(title)
Select ext
Case "pdf"
in.SetType("application/pdf")
Case "doc"
in.SetType("application/doc")
Case "docx"
in.SetType("application/docx")
End Select
in.SetComponent("android/com.android.internal.app.ResolverActivity")
StartActivity(in)
End If
End Sub
Sub GetExt(filename As String) As String
Dim ext As String
ext = filename.SubString(filename.LastIndexOf(".") + 1).ToLowerCase
Return ext
End Sub
Running the app on the tablet in Debug Mode produces the following results:
From the ListView, touch the song to open.
The "Open With" system dialog opens to select which app to view the file. I had installed the file reader called "ReadEra".
I selected this app, since it can open and view multiple file types and has no ads or in-app purchases.
A screen/app appears with the following statement...
Unable to perform request
content:/com.android.externalstorage.documents/tree/primary:Charts/Gospel Jam/A Daisy A Day.pdf
I press the Back button and it returns to my app. It did not open the file and my app did not crash.
A post from
@tsteward was able to open PDF files on this post
HERE.
I'll reach out to him and see what he has.
Regards,
Mark Stuart