【问题标题】:How to get IMEI number in blackberry 10 native如何在黑莓10本机中获取IMEI号码
【发布时间】:2014-10-20 14:22:50
【问题描述】:

我正在尝试在黑莓 10 原生中获取硬件设备的默认信息,所以基本上我正在尝试访问设备的 IMEISERIAL NUMBER。 p>

我尝试过使用以下代码

ma​​in.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);
}

ma​​in.qml

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

但是当我点击一个按钮时,我没有得到任何数据 IMEISerialNumber 而不是 imei序列号。但我总是遇到像

这样的错误
'_hardware' [undefined] is not an object.

注意:我已经在我的 .PRO

中添加了以下库
LIBS += -lbbsystem
LIBS += -lbbdevice
LIBS += -lbbdata

并获得对我的 XML 文件的许可。

read_device_identifying_information

我也通过许多链接进行了研究,例如,

【问题讨论】:

    标签: c++ qml blackberry-10 imei


    【解决方案1】:

    试试这个, ma​​in.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();
    }
    

    ma​​in.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 
            }
        ]
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-12-18
      • 2012-05-27
      • 2013-01-11
      • 2012-02-03
      • 2022-01-21
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多