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

    Can't find any photo on real devices

    Scheduled Pinned Locked Moved App Development
    8 Posts 4 Posters 737 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.
      • 0 Offline
        007fred50
        last edited by 007fred50

        Hello,

        I try to selected a photo in emulator it works well. But in real device i can't find any photo on my phone.

        import QtQuick 2.7
        import Ubuntu.Components 1.3
        //import QtQuick.Controls 2.2
        import QtQuick.Layouts 1.3
        import Qt.labs.settings 1.0
        import QtQuick.Window 2.12
        import QtQuick.Controls 2.5
        import QtQuick.Dialogs 1.2
        import Qt.labs.folderlistmodel 2.2
        
        MainView {
            id: root
            objectName: 'mainView'
            applicationName: 'ufile.ufile'
            automaticOrientation: true
        
            width: units.gu(45)
            height: units.gu(75)
        
            Column{
                anchors.verticalCenter: parent.verticalCenter
                anchors.horizontalCenter: parent.horizontalCenter
        
                Row{
                    Button {
                        id: btn
                        text: "Open"
                        onClicked: fileDialog.open();
                    }
                }
        
                Image {
                    id: setImg
                    width: 300
                    height: 300
                    source: ""
                }
        
                FileDialog {
                    id: fileDialog
                    title: "Please choose a file"
                    folder: shortcuts.home
                    onAccepted: {
                        var setFiles = fileDialog.fileUrls
                        console.log("You chose: " + fileDialog.fileUrls)
                        setImg.source = setFiles[0]
                        //Qt.quit()
                    }
                    onRejected: {
                        console.log("Canceled")
                        //Qt.quit()
                    }
                }
            }
        }
        

        Then i try to compile the .click file to Ubuntu Touch device i got this error here:

        Errors
        ------
         - security:policy_groups_safe:ufile:picture_files
        	(NEEDS REVIEW) reserved policy group 'picture_files': vetted applications only
         - security:policy_groups_valid:ufile:document_files
        	unsupported policy_group 'document_files'
        /home/fredy/Desktop/ubuntutouch/ufile/build/all/app/ufile.ufile_1.0.0_all.click: FAIL
        non-network local connections being added to access control list
        

        I have (clickable update) to the lastest

        Thanks for your time 🙂

        Best Reagrds
        007fred

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

          @007fred50 files are managed through ContentHub.
          You have a quick explanation here: https://docs.ubports.com/en/latest/appdev/guides/contenthub.html

          Another planet, another time, another universe!

          0 1 Reply Last reply Reply Quote 0
          • 0 Offline
            007fred50 @CiberSheep
            last edited by

            @cibersheep Hej, I have try the website and did not understand it.

            klhK 1 Reply Last reply Reply Quote 0
            • klhK Offline
              klh @007fred50
              last edited by klh

              @007fred50 You can't browse device files directly because of security rules, you have to request them through the ContentHub.

              The linked documentation also links to the source code of an app that uses it to select images: https://gitlab.com/cibersheep/webapp-creator/blob/master/webapp-creator/app/ImportPage.qml#L38

              Not sure about the last error, can you post your clickable.json and .apparmor file?

              0 1 Reply Last reply Reply Quote 1
              • 0 Offline
                007fred50 @klh
                last edited by

                @klh hello,

                Thanks for your time 🙂

                Here is my 3 fies.

                clickable.json:

                {
                  "clickable_minimum_required": "6.22.0",
                  "builder": "pure-qml-cmake",
                  "kill": "qmlscene"
                }
                

                I found this here (https://docs.ubports.com/en/latest/appdev/platform/apparmor.html#networking)

                and i set into (.apparmor)

                .apparmor:

                {
                    "policy_groups": ["camera", "document_files", "picture_files"],
                    "policy_version": 16.04
                }
                

                my Main.qml code:

                import QtQuick 2.7
                import Ubuntu.Components 1.3
                //import QtQuick.Controls 2.2
                import QtQuick.Layouts 1.3
                import Qt.labs.settings 1.0
                import QtQuick.Window 2.12
                import QtQuick.Controls 2.5
                import QtQuick.Dialogs 1.2
                import Qt.labs.folderlistmodel 2.2
                
                MainView {
                    id: root
                    objectName: 'mainView'
                    applicationName: 'ufile.ufile'
                    automaticOrientation: true
                
                    width: units.gu(45)
                    height: units.gu(75)
                
                    Column{
                        anchors.verticalCenter: parent.verticalCenter
                        anchors.horizontalCenter: parent.horizontalCenter
                
                        Row{
                            Button {
                                id: btn
                                text: "Open"
                                onClicked: fileDialog.open();
                            }
                        }
                
                        Image {
                            id: setImg
                            width: 300
                            height: 300
                            source: "/home/fredy/Pictures/Screenshot from 2021-10-22 11-29-16.png"
                        }
                
                        FileDialog {
                            id: fileDialog
                            title: "Please choose a file"
                            folder: shortcuts.home
                            onAccepted: {
                                var setFiles = fileDialog.fileUrls
                                console.log("You chose: " + fileDialog.fileUrls)
                                setImg.source = setFiles[0]
                                //Qt.quit()
                            }
                            onRejected: {
                                console.log("Canceled")
                                //Qt.quit()
                            }
                        }
                    }
                }
                

                Best Regards
                007fred50

                klhK 1 Reply Last reply Reply Quote 0
                • klhK Offline
                  klh @007fred50
                  last edited by klh

                  @007fred50 oh, I just checked, the last line has nothing to do with the build process, and the FAIL doesn't stop the build or upload (at least I was able to build with these policies).

                  Here you have a complete example of importing a file using ContentHub in QML: https://api-docs.ubports.com/sdk/apps/qml/Ubuntu.Content/ContentHub.html#detailed-description

                  Basically you have to create a ContentPeer:

                  ContentPeer {
                      id: picSourceSingle
                      contentType: ContentType.Pictures
                      handler: ContentHandler.Source
                      selectionType: ContentTransfer.Single
                  }
                  

                  Have a place to store the transfer:

                  property var activeTransfer
                  

                  Then in the click handler start the request:

                  onClicked: {
                      activeTransfer = picSourceSingle.request()
                  }
                  

                  And handle the transfer result:

                  Connections {
                      target: root.activeTransfer
                      onStateChanged: {
                          if (root.activeTransfer.state === ContentTransfer.Charged) {
                              setImg.source = root.activeTransfer.items[0].url;
                          }
                      }
                  }
                  

                  I adapted it a bit to your code, hopefully you are able to integrate it completely.

                  klhK 1 Reply Last reply Reply Quote 0
                  • klhK Offline
                    klh @klh
                    last edited by klh

                    @007fred50 looks like all my explaining was pointless, because it doesn't work now, picSourceSingle is always undefined no matter what I try. No idea why, maybe it's not supported anymore and the docs weren't updated.

                    If you still need a solution ContentPeerPicker works fine:

                    ContentPeerPicker {
                        anchors { fill: parent }
                        visible: parent.visible
                        showTitle: false
                        contentType: ContentType.All
                        handler: ContentHandler.Source
                    
                        onPeerSelected: {
                            picker.activeTransfer = peer.request()
                            picker.activeTransfer.stateChanged.connect(function() {
                                if (picker.activeTransfer.state === ContentTransfer.Charged) {
                                    console.log(picker.activeTransfer.items[0].url)
                                    picker.activeTransfer = null
                                }
                            })
                        }
                    }
                    

                    (example provided under the CC0 license)
                    You can show it in a dialog when user clicks a button.

                    A 1 Reply Last reply Reply Quote 0
                    • A Offline
                      Aloys @klh
                      last edited by

                      Hi,
                      If it helps, I did a sample app (with many comments) to manage import of a file with content hub, see:
                      https://gitlab.com/ubuntu-touch-applications/sample-applications/importwithcontenthub

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