如何使用UserMetric发布消息到Welcome Screen
2015-08-28 16:51
417 查看
我们可以通过UserMetric的API发布消息到我们手机的欢迎页面(手机的锁屏界面)。在锁屏界面中,我们可以双击中间的圆圈,来循环播放我们手机发布的消息。如下图所示,
我们发布了“Useermetric messages received: 4”个消息。
我们需要使用的模块是:
我们可以使用如下的方法得到它所有的API:
我们的应用非常简单:
为了使用UserMetric,我们必须在我们的应用中使用usermetrics security policy:
运行我们的应用:
每当我们点击increase按钮后,我们的欢迎界面数据将增加一个:
整个应用的源码在:https://github.com/liu-xiao-guo/usermetrics
我们发布了“Useermetric messages received: 4”个消息。
我们需要使用的模块是:
import UserMetrics 0.1
我们可以使用如下的方法得到它所有的API:
liuxg@liuxg:~$ qmlplugindump import UserMetrics 0.1QQmlComponent: Component is not ready
liuxg@liuxg:~$ qmlplugindump UserMetrics 0.1
import QtQuick.tooling 1.1
// This file describes the plugin-supplied types contained in the library.
// It is used for QML tooling purposes only.
//
// This file was auto-generated by:
// 'qmlplugindump UserMetrics 0.1'
Module {
Component {
name: "Metric"
prototype: "QObject"
exports: ["Metric 0.1"]
exportMetaObjectRevisions: [0]
Property { name: "name"; type: "string" }
Property { name: "format"; type: "string" }
Property { name: "emptyFormat"; type: "string" }
Property { name: "domain"; type: "string" }
Property { name: "minimum"; type: "double" }
Property { name: "maximum"; type: "double" }
Method {
name: "increment"
Parameter { name: "amount"; type: "double" }
}
Method { name: "increment" }
Method {
name: "update"
Parameter { name: "value"; type: "double" }
}
}
}
我们的应用非常简单:
Main.qml
import QtQuick 2.0
import Ubuntu.Components 1.1
import UserMetrics 0.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: "usermetrics.liu-xiao-guo"
/*
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(60)
height: units.gu(85)
Page {
title: i18n.tr("usermetrics")
Metric {
id: incomingMessagesMetric
name: "usermetric"
format: i18n.tr("Usermetric messages received today: %1")
emptyFormat: i18n.tr("No Usermetric messages received today.")
domain: applicationName
}
Column {
anchors.centerIn: parent
spacing: units.gu(2)
Button {
text: i18n.tr("Increase")
onClicked: {
console.log("Going to increase the metric!");
incomingMessagesMetric.increment()
}
}
Button {
text: i18n.tr("Decrease")
onClicked: {
console.log("Going to increase the metric bye 2!");
incomingMessagesMetric.increment(-2)
}
}
Button {
text: i18n.tr("Decrease")
onClicked: {
console.log("Going to update to 3 to the metric!");
incomingMessagesMetric.update(3)
}
}
}
}
}
为了使用UserMetric,我们必须在我们的应用中使用usermetrics security policy:
usermetrics.apparmor
{ "policy_groups": [ "networking", "webview", "usermetrics" ], "policy_version": 1.3 }
运行我们的应用:
每当我们点击increase按钮后,我们的欢迎界面数据将增加一个:
整个应用的源码在:https://github.com/liu-xiao-guo/usermetrics
相关文章推荐
- java之学习多线程(四)
- 【AHOI2009】【BZOJ1800】fly 飞行棋
- IOS学习和总结KVO
- 克鲁斯卡尔算法(模板)
- win8安装 Matlab,运行出现 this application has requested the runtime to terminate it in an unusual way .
- Java笔记学习总结(五)
- Python代码登录新浪微博并自动发微博
- 采用CAS原理构建单点登录
- SQL Server 触发器 详细讲解
- flex与C# Socket通信
- github的入门教程
- 清除网络共享文件夹密码缓存
- Docker中的镜像
- 框架整合笔记spring+mybatis+others
- C++中#ifndef#define#endif的用法
- 二叉树
- TTCN-3核心语言第一章与第二章
- ORA-00020: maximum number of processes (2000) exceeded
- eclipse中的Java项目引入jar包直接在根目录下
- 反射泛型方法