简体   繁体   English

如何在黑莓10本机中获取IMEI号码

[英]How to get IMEI number in blackberry 10 native

I am trying to get the Default information of Hardware device in blackberry 10 native, So basically i am trying to access IMEI or SERIAL NUMBER of the device. 我试图在黑莓10本机中获取硬件设备的默认信息,所以基本上我正在尝试访问设备的IMEISERIAL NUMBER

I havetried using following code 我使用以下代码

main.cpp 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 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 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 a button i am not getting any data either IMEI or SerialNumber instead of imei or serial number . 但是当我点击一个按钮时,我没有获得任何数据IMEISerialNumber而不是imei序列号 But always i am getting error like 但总是我得到错误

'_hardware' [undefined] is not an object.

Note: i have already added following library in my .PRO 注意:我已经在.PRO中添加了以下库

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

and following permission to my XML file. 以及对我的XML文件的以下权限。

read_device_identifying_information

I have also researched through many link like, 我也通过很多链接研究过,

Link1 , Link2 , Link3 and i have also read the official document of Blackberry but i am not getting proper way to achieve my task. Link1Link2Link3和我也阅读了Blackberry的官方文档,但我没有得到正确的方法来完成我的任务。

Try this, main.cpp 试试这个, 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 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 
        }
    ]
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM