Android Question Open files with default programs

vecino

Well-Known Member
Licensed User
Longtime User
Hi, how I can show images, text, pdf, etc. not knowing what program should open.
 

vecino

Well-Known Member
Licensed User
Longtime User
If it is a "pdf" then that is displayed with PDF reader.
If it is an image, then that is displayed with the viewer.
Etc.
 
Upvote 0

vecino

Well-Known Member
Licensed User
Longtime User
Hi, I guess my question should continue in this thread:

I have a list of files of various types. example:
aimage.jpg
apdf.pdf
anotherimage.png
avideo.mp4
atext.txt
etc.

The user adds files of any type.
The user touches an item from the list and I need to display the file with the default application.

How I can know what is the default application?
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
How I can know what is the default application?
You will need to set the intent mime type based on the file extension. It doesn't happen automatically.
So you need to extract the file extension and based on the extension you need to set the right filetype and call the openintent... If there is a program which has intent-filters for this filetype set it will be used. If there are more than one and the user does not set one FIXED the user can select one from the list.
 
Upvote 0

vecino

Well-Known Member
Licensed User
Longtime User
Thank you, so what do I put in the last "else"?
B4X:
Sub lvFiles_ItemClick (Position As Int, Value As Object)
   Dim cT, cExt, cDir As String
   Dim inttFile As Intent
   '
   cDir = globales.cDBpath
   '
   cT = Value
   cExt = cT.ToLowerCase.SubString( cT.LastIndexOf(".") )
   '
   inttFile.Initialize(inttFile.ACTION_VIEW, "file://" & File.Combine(cDir,cT))
   '
   If (cExt.CompareTo(".jpg")=0) OR (cExt.CompareTo(".png")=0) OR (cExt.CompareTo(".bmp")=0) Then
     inttFile.SetType("image/*")
   Else If cExt.CompareTo(".pdf")=0 Then
     inttFile.SetType("application/pdf")
   Else If cExt.CompareTo(".txt")=0 Then
     inttFile.SetType("text/plain")
   Else If (cExt.CompareTo(".htm")=0) OR (cExt.CompareTo(".html")=0) Then
     inttFile.SetType("text/html")
   else

    inttFile.SetType(" ??? ")  ' <---  ???

   End If
   '
   StartActivity( inttFile )
End Sub
 
Upvote 0
Top