标签:font 目的 root enables title deb cli span data-
在上面的一篇文章中,我们介绍了怎样使用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文件例如以下:
[Desktop Entry] Name=MyApp Exec=qmlscene $@ main.qml -- %u Icon=MyApp.png Terminal=false Type=Application X-Ubuntu-Touch=true
为了可以在程序中显示得到的URL信息,我们对程序做了例如以下的改动:
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"]
}我们直接创建一个主要的QML template应用,同一时候改动我们的main.qml例如以下:
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");
假设“MyApp”在已经执行的情况下。能够看到例如以下的右边的画面:
标签:font 目的 root enables title deb cli span data-
原文地址:http://www.cnblogs.com/cynchanpin/p/6892609.html