UBports Robot Logo UBports Forum
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Register
    • Login

    Using image from Content Hub

    Scheduled Pinned Locked Moved App Development
    7 Posts 3 Posters 719 Views 2 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
      Reply
      • Reply as topic
      Log in to reply
      This topic has been deleted. Only users with topic management privileges can see it.
      • M Offline
        Mick21367
        last edited by

        Hi,
        I've been going through the process of importing an image from the content hub by following the tips here:- https://docs.ubports.com/en/latest/appdev/guides/contenthub.html.
        It all works as expected (Yay!) but I have no idea how I can get the imported app to stay put following an app restart 😞 - in the example above the WebApp Creator app doesn't need to retain the imported image.
        Does anyone have any idea (or can point to links on) how to import the image permanently? I've had a look at the rest of the documentation and other apps which use the content hub, but haven't had any luck so far.
        The image is stored (temporarily) in the HubIncoming folder but that, of course, doesn't survive a restart.
        Thanks
        Mick

        AppLeeA 1 Reply Last reply Reply Quote 0
        • AppLeeA Offline
          AppLee @Mick21367
          last edited by AppLee

          @Mick21367 You are correct about what you witness.
          But that is only normal behavior.
          The content hub allows you to gain access to some data (picture, music, video, ...), how the data is used is up to the destination app.
          So it's up to you to save that picture within your app. I actually never done it, but there are some folders you can write permanent data (database, documents, etc.)

          [Edit] I did find the documentation I was thinking of :
          http://docs.ubports.com/en/latest/appdev/guides/writeable-dirs.html#standard-paths

          I suggest to use the App Data path to permanently store the images you import using the content hub.

          1 Reply Last reply Reply Quote 0
          • CiberSheepC Offline
            CiberSheep
            last edited by CiberSheep

            You have to copy the imported file or use move function from the ContentItem

            You have a commented example here

            Another planet, another time, another universe!

            M 1 Reply Last reply Reply Quote 0
            • M Offline
              Mick21367 @CiberSheep
              last edited by

              @CiberSheep Thanks for the link. Unfortunately, I still can't get it to work. I'm off to sleep now but if you get a chance, can you answer a couple of questions?
              How does the ContentItem move actually work? The documentation is less than clear, unfortunately. If possible, can you point me to a very simple example (sorry, I'm nowhere near clever enough to follow the example you gave!)?
              If it helps, the idea is that the user would replace a placeholder with an imported picture (a la Webapp Creator) and, if they wanted to, would click a button to permanently replace that placeholder - so the new picture would overwrite the old placeholder.
              Don't worry if this isn't possible - it's a learning experience for me rather than something remotely useful to anyone 🙂
              Thanks (and good night!)
              Mick

              CiberSheepC 1 Reply Last reply Reply Quote 0
              • CiberSheepC Offline
                CiberSheep @Mick21367
                last edited by

                @Mick21367 The ContentHub is quite confusing.

                The idea is:

                • When the peer is selected (that is, when user taps on an app to import the content) we ask the ContentHub to start the importation process.

                The important part is that we listen to stateChangeConnection state changes

                When the content (the picture in this case) is loaded we some actions. The interesting ones are: we go through the list of items imported and we could do a importPage.activeTransfer.items[i].move("[path]") were [path] is the path to a writable folder.

                This is one way of doing it. The other is using cpp. For example, in Gelek you can import a file

                StoreGameFile() is a function defined in cpp plugin

                Another planet, another time, another universe!

                M 1 Reply Last reply Reply Quote 2
                • M Offline
                  Mick21367 @CiberSheep
                  last edited by

                  @CiberSheep Thank you - I've finally (!) managed to move it to a writeable location :-). Just for info, the variation I used was
                  picker.activeTransfer.items[0].move("/home/phablet/.local/share/<app_name>/","picked")
                  as I'm only importing one picture.
                  A couple of extra questions - does anyone know if the above can be used to overwrite an existing file (the user may want to change the picture from time to time) or can the imported file (the one that we've moved) be deleted?
                  @CiberSheep Thanks again - your help has been invaluable 🙂

                  AppLeeA 1 Reply Last reply Reply Quote 1
                  • AppLeeA Offline
                    AppLee @Mick21367
                    last edited by

                    @Mick21367 You have creator rights in the writable folder so it's doable to replace or delete the imported file.

                    1 Reply Last reply Reply Quote 0
                    • First post
                      Last post