Battery Status in an application

I’ve made an app which has the battery icon and charging percentage, the data comes from “batteryStatus” which means importing “org.nemomobile.systemsettings” which is NOT allowed in harbour.

Is there another way to incorporate battery status into my app that will be acceptable in Harbour?

I realise that “peeking” to homescreen is the default way to view such data, but would prefer to show battery status in my app, just the percentage charged/discharging.


I would be in favor of this to add power saving in my app

There are dbus services from mce but I haven’t been able to call them successfully.
Maybe just listening on the signal works?

 nemo@PGXperiiia10:~ $ busctl tree
nemo@PGXperiiia10:~ $   busctl introspect /com/nokia/mce/signal | grep batt
.battery_level_ind                  signal    i         -            -
.battery_state_ind                  signal    s         -            -
.battery_status_ind                 signal    s         -            -
nemo@PGXperiiia10:~ $   busctl introspect /com/nokia/mce/request | grep batt
.get_battery_level                  method    -         i            -
.get_battery_state                  method    -         s            -
.get_battery_status                 method    -         s            -

This does get you the percentages, but only after they have changed :wink:

 dbus-monitor --system,,member=battery_level_ind

Or in QML:

import QtQuick 2.6
import Sailfish.Silica 1.0
import Nemo.DBus 2.0

ApplicationWindow {
    id: app
    property int battery
    DBusInterface {
        signalsEnabled: true
        bus: DBus.SystemBus
        service: ''
        path: '/com/nokia/mce/signal'
        iface: ''
        function battery_level_ind(v){ 
            console.debug ("Battery Level:", v)
            app.battery = v
    initialPage: Component { Page{
        SilicaFlickable {
            anchors.fill: parent
            Label {
                anchors.centerIn: parent
                font.pixelSize: 155
                text: app.battery
        } }

This Nokia-Appearances everywhere in SailfishOS is for me the true Sign, that SFOS is the real and natural successor of the Nokia-Line. My heard is filled with warm and pleasant joy! :grinning:

I came across “org.freedesktop.contextkit 1.0” module. This is allowed in harbour.

Add this to your .cpp file under <sailfishapp.h>

 #include <QQmlContext>

Then in your QML file/s, add the import statement

import org.freedesktop.contextkit 1.0

Now you can add the modules to your QML files for stuff like battery capacity, voltage, temperature, etc