How to get IMEI number in blackberry 10 native

I am trying to get default information on hardware device in blackberry 10 native, so basically I am trying to access IMEI or GRAY NUMBER of the device.

I used the following code

main.cpp

#include "applicationui.hpp"

#include <bb/cascades/Application>
#include <bb/device/HardwareInfo>

#include <QLocale>
#include <QTranslator>

#include <Qt/qdeclarativedebug.h>

using namespace bb::cascades;

Q_DECL_EXPORT int main(int argc, char **argv)
{
    qmlRegisterUncreatableType<bb::device::HardwareInfo>("bb.device", 1, 0, "HardwareInfo", "");
    Application app(argc, argv);
    ApplicationUI appui;
    return Application::exec();
}

      

applicationui.cpp

#include "applicationui.hpp"

#include <bb/cascades/Application>
#include <bb/cascades/QmlDocument>
#include <bb/cascades/AbstractPane>
#include <bb/device/HardwareInfo>
#include <bb/cascades/Label>

using namespace bb::cascades;
using namespace bb::device;

ApplicationUI::ApplicationUI() :
        QObject()
{
    HardwareInfo hwInfo;
    QmlDocument *qml = QmlDocument::create("asset:///main.qml").parent(this);
    qml->setContextProperty("_hardware", &hwInfo);
    AbstractPane *root = qml->createRootObject<AbstractPane>();
    Application::instance()->setScene(root);
}

      

main.qml

Page {
    Container {
        Label {
            id: showIMEI
        }
        Button {
            text: "Click me"
            onClicked: {
                showIMEI.text = "IMEI = " + _hardware.serialNumber;
                //showIMEI.text = "IMEI = " + _hardware.imei;
            }
        }
    }
}

      

but when i click the button i don't receive any IMEI or SerialNumber data instead of imei or serial number . But I always get an error like

'_hardware' [undefined] is not an object.

      

Note. I have already added the following library to my .PRO

LIBS += -lbbsystem
LIBS += -lbbdevice
LIBS += -lbbdata

      

and after getting permission to my XML file.

read_device_identifying_information

      

I also researched many links, for example

Link1 , Link2 , Link3 and I have also read the Blackberry whitepaper but I am not getting a proper path to accomplish my task.

+3


source to share


1 answer


Try this, main.cpp

#include "applicationui.hpp"

#include <bb/cascades/Application>
#include <bb/device/HardwareInfo.hpp>
#include <QLocale>
#include <QTranslator>

#include <Qt/qdeclarativedebug.h>

using namespace bb::cascades;
using namespace bb::device;

Q_DECL_EXPORT int main(int argc, char **argv)
{
    qmlRegisterType<HardwareInfo>("bb.device",1,0,"HardwareInfo");
    Application app(argc, argv);

    // Create the Application UI object, this is where the main.qml file
    // is loaded and the application scene is set.
    ApplicationUI appui;

    // Enter the application main event loop.
    return Application::exec();
}

      



main.qml

import bb.cascades 1.0
import bb.device 1.0
Page {
    Container {
        Label {
            id: label
            // Localized text with the dynamic translation and locale updates support
            text: qsTr("Hello World") + Retranslate.onLocaleOrLanguageChanged
            textStyle.base: SystemDefaults.TextStyles.BigText
            multiline: true
        }
        Button {
            onClicked: {
                label.text=hardwareinfo.imei 
                console.debug("imei\t"+hardwareinfo.imei)
                console.debug("serialNumber \t"+hardwareinfo.serialNumber)
            }
        }
    }
    attachedObjects:[
        HardwareInfo {
           id: hardwareinfo 
        }
    ]
}

      

+1


source







All Articles