So far, Bluetooth has not been formally supported on the Ubuntu platform. For some hacker-level developers, it may not be urgent. We are here to provide a way for everyone to taste fresh. The final platform will support Bluetooth. and the corresponding library will be installed into the platform.
To be able to run Bluetooth apps on your phone, we have to do the following:
The above sentence:
$ sudo mount-o rw,remount/
is to make our image readable and writable so we can install our QT Bluetooth library below
We pass the order:
$ sudo apt-get install Qml-module-qtbluetooth
To install the corresponding QT Bluetooth library.
Since Bluetooth is not fully supported at the moment, there is no corresponding security policy corresponding to it. In our test application, we must adapt to the "unconfined" Template:
Bluetooth.apparmor
{"
policy_groups": [
"Networking",
"WebView",
"Connectivity"
],
"policy_version": 1.3,
"template": "Unconfined"
}
SCANNER.QML
Import QtQuick 2.0 Import Qtbluetooth 5.2 Item {id:top property bluetoothservice currentservice Bluetooth
Discoverymodel {Id:btmodel running:true discoveryMode:BluetoothDiscoveryModel.DeviceDiscovery OnDiscoveryModeChanged:console.log ("Discovery mode:" + discoverymode) OnServiceDiscovered:console.log ("
Found new Service "+ service.deviceaddress +" "+ service.devicename +" + service.servicename); OnDeviceDiscovered:console.log ("New device:" + device) onerrorchanged: {switch (btmodel.error) {Case BluetoothDiscoveryModel.PoweredOffError:console.log ("Error:bluetooth device n OT turned on ");
Break Case BluetoothDiscoveryModel.InputOutputError:console.log ("Error:bluetooth I/O Error");
Break Case BluetoothDiscoveryModel.InvalidBluetoothAdapterError:console.log ("Error:invalid BlUetooth Adapter Error ");
Break
Case BluetoothDiscoveryModel.NoError:break; Default:console.log ("Error:unknown Error");
Break
}}} Rectangle {id:busy width:top.width * 0.7;
Anchors.horizontalCenter:parent.horizontalCenter Anchors.top:top.top;
height:text.height*1.2; Radius:5 color: "#1c56f3" visible:btModel.running text {id:text text:
"Scanning" Font.bold:true font.pointsize:20 anchors.centerIn:parent} Sequentialanimation on color {id:busythrobber ColorAnimation {easing.type:Easing.InOutSin E From: "#1c56f3"; To: ' White '; duration:1000; } ColorAnimation {easing.type:Easing.InOutSine; to: ' #1c56f3 '; From: ' White '; duration:1000} l
Oops:Animation.Infinite }} ListView {id:mainlist width:top.width anchors.top:busy.bottom anchors.bo Ttom:buttonGroup.top anchors.bottommargin:10 anchors.topmargin:10 clip:true MODEL:BT Model delegate:rectangle {id:btdelegate width:parent.width height:column.
Height + Ten property bool Expended:false;
Clip:true Image {Id:bticon Source: "Images/default.png";
Width:bttext.height;
Height:bttext.height;
Anchors.top:parent.top Anchors.left:parent.left Anchors.margins:5}
Column {id:column Anchors.left:bticon.right Anchors.leftmargin:5
Text {id:bttext text:devicename? devicename:name font.family: "Freeserif" font.pointsize:16} Text { Id:details function Get_details (s) {if (Btmodel.discoverymode = =
Bluetoothdiscoverymodel.devicediscovery) {//we is doing a device discovery
var str = "Address:" + remoteaddress;
return str;
} else {var str = "Address:" + s.deviceaddress;
if (s.servicename) {str + = "<br>service:" + s.servicename;}
if (s.servicedescription) {str + = "<br>description:" + s.servicedescription;}
if (s.serviceprotocol) {str + = "<br>protocol:" + s.serviceprotocol;}
return str; }} visible:opacity !== 0 opacity:btDelegate.expended? 1:0.0 text:get_details (Service) font.family: "Freeserif" fo
Nt.pointsize:14 Behavior on opacity {numberanimation {duration:200}
}}} Behavior on height {numberanimation {duration:200}} Mousearea {anchors.fill:parent onClicked:btDelegate.expended =!btdelegate.expen Ded}} Focus:true} Row {Id:buttongroup property var Activebutton : Devbutton anchors.bottom:parent.bottom anchors.horizontalCenter:parent.horizontalCenter Ancho
Rs.bottommargin:5 spacing:10 Button {Id:fdbutton width:top.width/3*0.9 Mdbutton has longest text height:mdButton.height text: "Full Discovery" OnClicked:btModel.discoveryMode = bluetoothdiscoverymodel.fullservicediscovery}
button {Id:mdbutton width:top.width/3*0.9 text: "Minimal Discovery"
OnClicked:btModel.discoveryMode = Bluetoothdiscoverymodel.minimalservicediscovery} Button { Id:devbutton width:top.width/3*0.9//mdbutton has longest text height:mdbutton.h Eight text: "Device Discovery" OnClicked:btModel.discoveryMode = Bluetoothdiscoverymodel.devicedi
Scovery}}}
For the introduction of Bluetoothdiscoverymodel, the developer can directly refer to the QT documentation to do a more step-on understanding.
To run our application:
The source code for the entire application is: Https://github.com/liu-xiao-guo/bluetooth