Examples for sharing api

Hi
i just wanted to update my apps and fix sharing again.
i was just sharing links and text, no files
i did not find any examples, nothing
like here: nothing Apps | Sailfish OS Documentation
i do not want to implement an consumer or plugin
just share from my app to i.e. mail or sms
currently i can trigger sharing but seems i need to create a file, which i dont need.
i just need to share a piece of text.
with transferengine i did just place the text into data property, defined the mime type and done.
this does not work. i can start sharing but both mail and blueetooth seems to expect and file

see info https://forum.sailfishos.org/t/sailfish-share-api-and-sailfish-webview/8494

1 Like

The API documentation is also available offline in the Sailfish IDE.

2 Likes
                     shareAction.resources = [ {
                         "data": listToShare,
                         "name": "the list"
                     } ]
                     shareAction.trigger()

does not work for me.
list to share a piece of text, a multiline string.
no share dialog does pop up.

Did you set the mimeType and title too?

i have created a shareaction in qml and set the title there.
i did try to set mimeType in vaious combinations, and the last time without
as docu says: if no mimetype set, then rawdata will be evaluated
i have tried like dozen combinations
dialog did only open when the framework thought i am going to share a file, but that failed then of course in the subsequent exeuction …

        MenuItem {
            text: qsTr("Share")
            ShareAction {
                id: shareAction
                title: "hallo"
                //mimeType: "text/plain"
            }
            onClicked: {
                if (shoppingModel.count > 0)
                {
                    var listToShare = "";
                    for (var i=0; i< shoppingModel.count; i++) {
                        var oneItemAsString = shoppingModel.get(i).name + " " + shoppingModel.get(i).amount
                        listToShare += "\n" + oneItemAsString // here newline instead
                    }
                    var content = {
                        "data": listToShare,
                        "name": "the list"
                    }
                    // content["status"] = listToShare;
                    // content["linkTitle"] = "the list title";
                    // content["name"] = "the list";

                     shareAction.resources = [ {
                         "data": listToShare,
                         "name": "the list"
                     } ]
                     shareAction.trigger()
                }
            }
        }

The following code will give you the share plugin for one piece of text (based on the code in the jolla-office (Documents) app)

      ShareAction {id:share
           mimeType: filePage.mimeType 
           title: "text to share"
      }

      IconButton { id: sharebutton
           anchors.verticalCenter: parent.verticalCenter
           icon.source: "image://theme/icon-m-share"
           width: parent.height * 0.8
           height: parent.height

           onClicked: {
               share.resources = ["some text"]
               share.trigger()
           }
       }

from emulator:
share text.PNG

I didn’t succeed in sharing a list…

thanks ! that is basically what i do.
the open question is : - the mime type and if my string with new-lines is a problem
i will try with a simple string

i have now put a string directly into the array and use text/plain or text/* as mimetype
still nothing

no success
if i do what you did and share it to e-mail. result is: e-mail with an non-existing attachment with name some text to share

would be great if some sailor could share a piece of code.
wasting hours here for nothing
even had look on browser but found no shareaction example there

            MenuItem {
                text: qsTr("Share")
                ShareAction { id:share
                     mimeType: "text/*"
                     title: qsTr("Share event")
                }
                // icon: con-m-share
                onClicked: {
                    print(upcommingList.currentIndex)
                    var current = upcomingModel.get(upcommingList.currentIndex)
                    var he = {}
                    he.data = current.uri
                    he.name = "Hey, check this out"
                    share.resources = [he]
                    share.trigger()
                }
            }

so this does create an attachment for mail client with the uri as content (value of data) and file name as per value in name

not great but at least something

It looks like the WebShareAction in /usr/lib/qt5/qml/Sailfish/WebView/Popups handles the sharing of text and url. But no success :frowning:

thanks for trying.
i had a look on browswr code last week and saw that its not using the share action :slight_smile: so i did not continue in that direction.

with transferengine, it was possible to send a piece of code to maiö, sms or code.

now not sure how.
thw documentation is poor.

You can check OSM Scout code. https://github.com/Karry/osmscout-sailfish
Maybe Karry’s implementations will be ok for you.

Documentation is indeed poor. I’m curious how to share a list…

Managed to get the email opened with the code found in https://github.com/sailfishos/sailfish-components-webview/blob/master/import/popups/ContextMenu.qml. A new email is opened with both root.linkHref and root.linkTitle as plain text.

Then I tried the WebShareAction: copied the whole content of the file to my page and added the import.
When I use

shareAction.shareText("text to share")

the share dialog is opened with choices bluetooth and email …
hope this helps

1 Like

when adding the hidden property linkTitle, i can share to e-mail and see the link in mail body

                onClicked: {
                    print(upcommingList.currentIndex)
                    var mimeType = "text/x-url";
                    var current = upcomingModel.get(upcommingList.currentIndex)
                    var he = {}
                    he.data = current.uri
                    he.type = mimeType
                    he["linkTitle"] = current.uri
                    //he.name = "Hey, check this out"
                    shareAction.mimeType = mimeType
                    shareAction.resources = [he]
                    //shareAction.shareText("text to share")
                    shareAction.trigger()
                }

hope they implement a share to clipboard plugin as part of sfos too.

Why you need share to clipboard?
If you copy something to clipboard you can paste it wherever you want.

the only native telegram app that used to suport sharing was depecher, which is 2 years now obsolete.
if i now want to share a link to a concert from my app, or the whole shopping list …
how do i do that ?
currently not at all, there is no copy of text in apps, right ?
so i have a app like sailkick and i want to share an event to say: fernschreiber
how do i do that ?
not at all, i can open event in browser then copy url and then paste it, but wow what a ux.
so if i can share to clipboard, i can paste it super quick to anything
and there used to be a working plugin once …

Enabling copying in apps is really easy.
I just throw this in whatever i want to make copyable.

2 Likes