iOS Tutorial Open local files with external apps

Discussion in 'iOS Tutorials' started by Erel, Mar 18, 2015.

  1. Erel

    Erel Administrator Staff Member Licensed User

    iPhone library v1.40 includes a new object type named DocumentInteraction.

    With this controller you can allow the user to open a local file with an external app (this is the other side of this tutorial: http://www.b4x.com/android/forum/threads/open-external-files-with-your-app.50525/#content).

    [​IMG]

    Using DocumentInteraction is pretty simple. You initialize it with the file that you want to open and then call DocumentInteraction.OpenFile.

    You can optionally set the file type with the UTI property. The system types are listed here: https://developer.apple.com/library...fiers.html#//apple_ref/doc/uid/TP40009259-SW1

    Code:
    Sub Process_Globals
       
    Public App As Application
       
    Public NavControl As NavigationController
       
    Private Page1 As Page
       
    Private di As DocumentInteraction
    End Sub

    Private Sub Application_Start (Nav As NavigationController)
       NavControl = Nav
       Page1.Initialize(
    "Page1")
       Page1.RootPanel.Color = 
    Colors.Green
       NavControl.ShowPage(Page1)
       di.Initialize(
    "di"File.DirAssets, "Workbook.xls"'<--- open a file from the assets folder
    End Sub

    Sub Page1_Click
       di.OpenFile(Page1.RootPanel)
    End Sub

    Sub di_Closed
       
    Log("Dialog closed")
    End Sub

    Sub di_SendingFile
       
    Log("Opening file")
    End Sub
     
  2. falbertini

    falbertini Member Licensed User

    Thanks, that's what I need..

    I tried it now, for example with a xls file but worked only once... In my Iphone 4S I installed Microsoft Excel and in the dialog I choosed "Open in Excel".. One time worked, other times closed my app and returned to the main Iphone screen.
    Tried with other extensions (for example .doc .docx with Word) but closes my app and returned to the main Iphone screen
    Is there a way to catch if the file was opened correctly ?

    The code I use is this:
    Code:
    Dim di As DocumentInteraction
    di.Initialize(
    "di", folderName, fileName)
    di.OpenFile(f.RootPanel)
     
  3. Erel

    Erel Administrator Staff Member Licensed User

    Make sure that the variable (di) is a global variable.

    Your app might be killed while it is in the background. Therefore it is better to test this scenario in release mode.
     
  4. cengolo

    cengolo Member Licensed User

    this does not open the MOV file in default system player. where am i wrong?

    di.Initialize("di", File.DirAssets, "buk1.mov")
    di.UTI="com.apple.quicktime-movie (kUTTypeQuickTimeMovie)"
    di.OpenFile(Page1.RootPanel)
     
  5. Erel

    Erel Administrator Staff Member Licensed User

    It should be "com.apple.quicktime-movie". Though it is possible that no player is registered for this UTI. You can use VideoView to play the video inside your app.
     
  6. cengolo

    cengolo Member Licensed User

    what i want is not to play the video inside the app (since the app is only a webview actually) but to open the video in the system player externally. so when the user watches the video and click finish, i return to the app where it stayed. does videoview do that?
     
  7. Erel

    Erel Administrator Staff Member Licensed User

    VideoView will return to your app when the user closes it.
     
  8. cengolo

    cengolo Member Licensed User

    ok, how can i start a video in videoview automaticaly fullscreen
     
  9. Erel

    Erel Administrator Staff Member Licensed User

    Please start a new thread for this question.
     
  10. n3t

    n3t Member Licensed User

    If no app is register for a certain file type DI will not start and no event is raised.
    How we can detect this issue?

    thanks
     
  11. Erel

    Erel Administrator Staff Member Licensed User

  12. n3t

    n3t Member Licensed User

  13. n3t

    n3t Member Licensed User

    I get a conversion error on value returned by di.OpenFile:

    Application_Start
    Application_Active
    An error occurred:
    (Line: 41) 41
    java.lang.RuntimeException: Cannot parse: as boolean

    with code
    Dim res As Boolean = di.OpenFile(Panel1)
    If res = False Then
    hd.ToastMessageShow("No app present!", "")
    End If

    or

    If di.OpenFile(Panel1) = False Then
    hd.ToastMessageShow("No app present!", "")
    End If
     
  14. tucano2000

    tucano2000 Active Member Licensed User

    With Document Iteration is possible to directly open an application without showing a list and send parameters ?
     
  15. n3t

    n3t Member Licensed User

  16. Erel

    Erel Administrator Staff Member Licensed User

    Are you using the hosted builder or a local builder?
     
  17. tucano2000

    tucano2000 Active Member Licensed User

  18. n3t

    n3t Member Licensed User

    Hosted builder
     
  19. Erel

    Erel Administrator Staff Member Licensed User

    @n3t have you copied the xml file to internal libraries folder?

    @tucano2000 in most cases it works properly without setting the type. Have you tried it?
     
  20. tucano2000

    tucano2000 Active Member Licensed User

    I already tried without using the type but still shows a dialog and the list of applications
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice