Android Question Open files with default programs

Discussion in 'Android Questions' started by vecino, Jun 5, 2015.

  1. vecino

    vecino Well-Known Member Licensed User

    Hi, how I can show images, text, pdf, etc. not knowing what program should open.
     
  2. vecino

    vecino Well-Known Member Licensed 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.
     
  3. Erel

    Erel Administrator Staff Member Licensed User

    You will need to set the intent mime type based on the file extension. It doesn't happen automatically.
     
  4. vecino

    vecino Well-Known Member Licensed User

    Thanks, I understand :)
     
  5. vecino

    vecino Well-Known Member Licensed User

    Hi, I guess my question should continue in this thread:

    I have a list of files of various types. example:
    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?
     
  6. DonManfred

    DonManfred Expert Licensed User

    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.
     
  7. vecino

    vecino Well-Known Member Licensed User

    Thank you, so what do I put in the last "else"?
    Code:
    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")=0OR (cExt.CompareTo(".png")=0OR (cExt.CompareTo(".bmp")=0Then
         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")=0OR (cExt.CompareTo(".html")=0Then
         inttFile.SetType(
    "text/html")
       
    else

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

       
    End If
       
    '
       StartActivity( inttFile )
    End Sub
     
Loading...