Ability to toggle airplane / flight mode within an app
-
Hi everyone,
I'm new to UbPorts development and I'm wondering if it is possible for a QML app to toggle the flight mode?I searched the web and the forum and found nothing.
By the way, let me introduce myself:
I used to code in C/C++ and QT, I'm learning QML and UbPort development to create the missing apps for my UbPorts phone (Nexus 5).
I switched to UbuntuTouch end of 2017 and I only created webapps for my personal use.
I intend to contribute this year with full apps and few useful webapps for French people (banking, news, ...)My first project is a client for domoticz (https://www.domoticz.com server for home automation)
-
@AppLee Hi ! Maybe you can have a look to oFono, it is the app that is controlling the modem. In the documentation there is :
Flight Mode
- Flight Mode support. oFono uses the 'Online' property on the Modem interface
that controls the state of the radio. When Online state is False, all
interfaces that depend on the radio being on are removed. Other interfaces
enter reduced functionality mode where only certain actions are available
that do not depend on the radio. E.g. setting various settings on the local
You can use D-bus message for putting the radio on or off:
here you have the related d-Bus message :
https://github.com/intgr/ofono/blob/master/doc/modem-api.txtProperties boolean Powered [readwrite]
Boolean representing the power state of the modem device. boolean Online [readwrite] Boolean representing the rf state of the modem.
Online is false in flight mode.
- Flight Mode support. oFono uses the 'Online' property on the Modem interface
-
And what about WiFi? Flight mode is more than just ofono radio
-
@AppLee Why does your app need control of radio devices on the phone? Flight mode toggle is easily accessible from the top drop-down.
If your app needs to check connectivity status, you should use the
Ubuntu.Connectivity
API from QML. You can check that network is available and show an error page when it's not, before performing tasks requiring network access. -
@AlainW94 Thanks for the lead. I'm looking into this.
@dobey I would like to trigger a network event on domoticz and right after toggle the flight mode.
I would like the app to be able to switch it off if connectivity is unavailable.
I already looked aboutUbuntu.Connectivity
to detect whether I can communicate with domoticz server or not.If you can think of a hack or something I found it weird that this feature is unavailable to developers ???
If there is a good reason I'm curious to know it, I like to understand when I'm stuck with a puzzle.Thanks for your help
-
@AppLee You cannot control flight mode from your app because that would allow your app to effect the connectivity of not only other apps, but the system itself.
The app itself cannot disable flight mode, or connect to a network. However, you can show a warning and direct the user to enable network connectivity. Even if the radio is on, it doesn't guarantee you'll be able to connect to any specific domain. The route could be blocked for any number of reasons, and your app should deal with such errors in connection as well.
Something like this as a component for swapping out an error page with real content when connectivity changes, should do.
import QtQuick 2.7 import Ubuntu.Connectivity 1.0 Item { Loader { id: pageLoader asynchronous: true anchors.fill: parent source: Connectivity.online ? "RealPage.qml" : "OfflinePage.qml" } Connections { target: Connectivity onOnlineChanged: { pageLoader.setSource(Connectivity.online ? "Realpage.qml" : "OfflinePage.qml"); } } }
-
@dobey Thanks Dobey, now I understand why I cannot do it.
I published a first release of my app without this feature and after giving it more thoughts I'm not sure it would have been useful.
I appreciate the answer!