簡體   English   中英

如何在黑莓10本機中獲取IMEI號碼

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

我試圖在黑莓10本機中獲取硬件設備的默認信息,所以基本上我正在嘗試訪問設備的IMEISERIAL NUMBER

我使用以下代碼

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;
            }
        }
    }
}

但是當我點擊一個按鈕時,我沒有獲得任何數據IMEISerialNumber而不是imei序列號 但總是我得到錯誤

'_hardware' [undefined] is not an object.

注意:我已經在.PRO中添加了以下庫

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

以及對我的XML文件的以下權限。

read_device_identifying_information

我也通過很多鏈接研究過,

Link1Link2Link3和我也閱讀了Blackberry的官方文檔,但我沒有得到正確的方法來完成我的任務。

試試這個, 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 
        }
    ]
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM