标签:des style blog http io color os ar 使用
在上面的一篇文章中,我们介绍了如何使用URL disptacher。在这篇文章中,我们来通过一个范例更进一步来了解如何实现它。
[ { "protocol": "launchmyapp" } ]
Qt.openUrlExternally("launchmyapp:///123");
{ "architecture": "all", "description": "description of MyApp", "framework": "ubuntu-sdk-14.10-dev2", "hooks": { "MyApp": { "apparmor": "MyApp.apparmor", "desktop": "MyApp.desktop", "urls": "MyApp.url-dispatcher" } }, "maintainer": "XiaoGuo, Liu <xiaoguo.liu@canonical.com>", "name": "com.ubuntu.developer.unknown.myapp", "title": "MyApp", "version": "0.1" }
[Desktop Entry] Name=MyApp Exec=qmlscene $@ main.qml -- %u Icon=MyApp.png Terminal=false Type=Application X-Ubuntu-Touch=true
import QtQuick 2.0 import Ubuntu.Components 1.1 /*! \brief MainView with a Label and Button elements. */ MainView { id:root // objectName for functional testing purposes (autopilot-qt5) objectName: "mainView" // Note! applicationName needs to match the "name" field of the click manifest applicationName: "com.ubuntu.developer.unknown.myapp" Component.onCompleted: { mylabel.text = "aaaa"; console.log( "arg length: " + myarg.arguments.length ); if ( myarg.defaultArgument === undefined) { mylabel.text = "undefined"; } else { mylabel.text = "args: " + myarg.defaultArgument.at(0); } console.log("argument: " + myarg.defaultArgument.at(0)); console.log("") } Arguments { id: myarg defaultArgument.help: "Expects URL of the media to play." defaultArgument.valueNames: ["URL"] } /* This property enables the application to change orientation when the device is rotated. The default is false. */ //automaticOrientation: true // Removes the old toolbar and enables new features of the new header. useDeprecatedToolbar: false width: units.gu(50) height: units.gu(75) Page { title: i18n.tr("MyApp") Column { spacing: units.gu(1) anchors { margins: units.gu(2) fill: parent } Row { spacing: units.gu(2) Label { id: mylabel objectName: "label" text: i18n.tr("Received parameters: ") } Label { id: label objectName: "label" text: i18n.tr("") } Connections { target: UriHandler onOpened: { // root.applicationName = "good" mylabel.text = "dddddd"; var para = ""; for (var i = 0; i < uris.length; ++i) { // application.parseArgument(uris[i]) console.log( uris[i] ); para += uris[i]; } label.text = para; } } } } } }
Arguments { id: myarg defaultArgument.help: "Expects URL of the media to play." defaultArgument.valueNames: ["URL"] }
import QtQuick 2.0 import Ubuntu.Components 1.1 /*! \brief MainView with a Label and Button elements. */ MainView { // objectName for functional testing purposes (autopilot-qt5) objectName: "mainView" // Note! applicationName needs to match the "name" field of the click manifest applicationName: "com.ubuntu.developer.unknown.launchmyapp" /* This property enables the application to change orientation when the device is rotated. The default is false. */ //automaticOrientation: true // Removes the old toolbar and enables new features of the new header. useDeprecatedToolbar: false width: units.gu(100) height: units.gu(75) Page { title: i18n.tr("LaunchMyApp") Column { spacing: units.gu(1) anchors { margins: units.gu(2) fill: parent } Button { objectName: "button" width: parent.width text: i18n.tr("Launch MyApp") onClicked: { Qt.openUrlExternally("launchmyapp:///123"); } } Button { objectName: "button" width: parent.width text: i18n.tr("Open MyApp") onClicked: { Qt.openUrlExternally("appid://com.ubuntu.developer.unknown.myapp/MyApp/current-user-version"); } } } } }
Qt.openUrlExternally("launchmyapp:///123");
Qt.openUrlExternally("appid://com.ubuntu.developer.unknown.myapp/MyApp/current-user-version");
标签:des style blog http io color os ar 使用
原文地址:http://blog.csdn.net/ubuntutouch/article/details/40538643