Nfc_ndef_record_t convert QByteArray HowTo

in one of my applications, I use NFC with custom instead of the record to the text file Type to be able to invoke my app since the NFC Tag directly.

Also, within my application, there is a feature allowing the user to write these Tags NFC

I would like to use an InvokeActionItem to use the sys. NFCViewer - I love the beautiful UI of it.

For my text NFC files, it works well.

Here's the InvokeActionItem:

       InvokeActionItem {
            imageSource: "asset:///images/ic_add.png"
            title: qsTr("NFC Tag Text")
            enabled: nfcActionSelector.selectedValue > 0
            ActionBar.placement: ActionBarPlacement.OnBar
            query {
                mimeType: "application/vnd.rim.nfc.ndef"
                invokeTargetId: "sys.NFCViewer"
                invokeActionId: "bb.action.SHARE"
            }
            handler: InvokeHandler {
                id: shareHandler
                onInvoking: {
                    tagWriteAction.data = app.getNdefTextMessage("en", nfcText);
                    shareHandler.confirm();
                }
            }
        }

This works well using a QByteArray:

QByteArray ApplicationUI::getNdefTextMessage(const QVariant &lang,
        const QVariant &text) {
    QString ndefLang = lang.toString();
    QString ndefText = text.toString();
    QtMobilitySubset::QNdefRecord ndefRecord = QtMobilitySubset::QNdefRecord();
    int langLength = (ndefLang.length() <= 63) ? ndefLang.length() : 63;
    QByteArray ndefPayload;
    ndefPayload[0] = langLength;
    ndefPayload.append(ndefLang.left(langLength)).append(ndefText.toUtf8());
    ndefRecord.setTypeNameFormat(QtMobilitySubset::QNdefRecord::NfcRtd);
    QByteArray nfcRtdText = "T";
    ndefRecord.setType(nfcRtdText);
    ndefRecord.setPayload(ndefPayload);
    QtMobilitySubset::QNdefMessage ndefMessage = QtMobilitySubset::QNdefMessage(
            ndefRecord);
    return ndefMessage.toByteArray();
}

So far so good

Now, I wanted to implement similar but using a recording of NFC Custom type.

This application example

has a method to create a record custom:

nfc_ndef_record_t* ApplicationUI::makeCustomRecord(QString domain, QString type,
        QString content) {

    nfc_ndef_record_t* record = 0;

    int textLen = content.length();
    QString domainPlusType = domain.append(":");
    domainPlusType = domainPlusType.append(type);
    int totalLen = textLen;

    uchar_t payload[totalLen];

    int offset = 0;
    memcpy(&payload[offset], content.toUtf8().constData(), textLen);

    CHECK(
            nfc_create_ndef_record(NDEF_TNF_EXTERNAL,
                    domainPlusType.toUtf8().constData(), payload, totalLen, 0,
                    &record));

    return record;
}

Unfortunately, I'm a nfc_ndef_record_t but need a QByteArray, use the same InvokeActionItem way in which regards NFC text documents.

Who knows how to convert the nfc_ndef_record_t in QByteArray?

thx for the help

Thanks to the help John Murray on twitter (@jcmrim) I'm creating a QNdefRecord:

QByteArray ApplicationUI::makeCustomRecord(QString domain, QString type,
        QString content) {

    QString domainPlusType = domain.append(":");
    domainPlusType = domainPlusType.append(type);

    QtMobilitySubset::QNdefRecord ndefRecord = QtMobilitySubset::QNdefRecord();

    ndefRecord.setTypeNameFormat(QtMobilitySubset::QNdefRecord::ExternalRtd);
    ndefRecord.setType(domainPlusType.toUtf8());
    ndefRecord.setPayload(content.toUtf8());

    QtMobilitySubset::QNdefMessage ndefMessage = QtMobilitySubset::QNdefMessage(
            ndefRecord);

    return ndefMessage.toByteArray();
}

Now the sys. Rises in NFCViewer:

InvokeActionItem {
            imageSource: "asset:///images/ic_add.png"
            title: qsTr("NFC Custom")
            ActionBar.placement: ActionBarPlacement.OnBar
            query {
                mimeType: "application/vnd.rim.nfc.ndef"
                invokeTargetId: "sys.NFCViewer"
                invokeActionId: "bb.action.SHARE"
            }
            handler: InvokeHandler {
                id: shareHandler2
                onInvoking: {
                    tagWriteAction.data = app.makeCustomRecord("org.xxxx", "mytype", nfcText);
                    shareHandler2.confirm();
                }
            }
        }

But if by tapping a NFC Tag I get

The data could not be shared over NFC

Any idea?

Or the NFCViewer not accept ExternalRtd?

documentation :

NDEF message is sent in the form of a byte array. The following method is used to create the byte array message:

It works with text documents

Or I do something wrong to build the payload or the record?

Tags: BlackBerry Developers

Similar Questions

  • Convert QByteArray QImage

    Hi all

    Is it possible to convert QByteArray QImage?

    Answer please!

    See you soon!

    use the registration method.

    example of http://qt-project.org/doc/qt-4.8/qimage.html#save-2

    QImage image;
    QByteArray ba;
    QBuffer buffer(&ba);
    buffer.open(QIODevice::WriteOnly);
    image.save(&buffer, "PNG"); // writes image into ba in PNG format
    
  • How to convert QByteArray QImage?

    Hello

    Anyone know how to convert QByteArray QImage?

    You can use this:

    QImage img = getAnImage();
    QByteArray arr;
    QBuffer buf(&arr);
    buf.open(QIODevice::WriteOnly);
    img.save(&buf, "PNG");
    buf.close();
    
  • Loading XML data in ListView of C++ after extraction of http data

    I'm sorry did searh but could not find any refrence related to my problem
    I am trying to load the xml data returned from a web service HTTP Post QNetworkRequest and QNetworkReply in c ++.

    My XML that gets donwloaded is as

    
     http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://tempuri.org/">
      
        tu7652
        F
        Marry
        Wijaya
      
      
        23
        F
        Marry
        Wijaya
      
    
    

    In My QML, it comes to the ListView can say SearchResult.qml

    ListView {
              objectName: "resultlist"
              dataModel: feedsdatamodel
              listItemComponents: [
                ListItemComponent {
                            type: "item"
                            PeopleListItem {
                                name: ListItemData.givenName + ", " + ListItemData.sn
                                role: ListItemData.ExtFunction
                                leftPaddingText: 40
                            }
                        }
               ]
            }
     attachedObjects: [
           // The data model that contains the content of a XML file
            GroupDataModel {
                id: feedsDataModel
                sortingKeys: [
                    "givenName"
                ]
                grouping: ItemGrouping.None
            }
        ]
    

    PeopleListItem.qml

    import bb.cascades 1.0
    
    Container {
        property alias name: titleLabel.text
        property alias role: functionLabel.text
        property alias leftPaddingText: textcontainer.leftPadding
    
        layout: StackLayout {
            orientation: LayoutOrientation.TopToBottom
        }
        preferredWidth: 768
        preferredHeight: 135
        Container {
    
            id: textcontainer
            topPadding: 10
    
            layout: StackLayout {
                orientation: LayoutOrientation.TopToBottom
            }
            Label {
    
                id: titleLabel
                textStyle.base: SystemDefaults.TextStyles.TitleText
                textStyle.color: Color.Black
            }
            Label {
                id: functionLabel
                textStyle.base: SystemDefaults.TextStyles.BodyText
                textStyle.color: Color.Gray
            }
        }
        Divider {
            verticalAlignment: VerticalAlignment.Bottom
        }
    }
    

    This is the function I'm using to display the QML it is called from main.qml and works correctly.

    void PeopleFinder::onSearchClicked() {
        qDebug() << "PeopleFinder::PeopleFinder::onSearchClicked::\t" << "begin";
        qDebug() << "PeopleFinder::PeopleFinder::onSearchClicked::\tfname:"
                << m_fname << "\tlname:" << m_lname;
    
        // Create a network access manager and connect a custom slot to its
        // finished signal
        mNetworkAccessManager = new QNetworkAccessManager(this);
    
        // create a data model with sorting keys for lastname and firstname
        Q_ASSERT(
                connect(mNetworkAccessManager, SIGNAL(finished(QNetworkReply*)), this, SLOT(requestFinished(QNetworkReply*))));
    
        //Load the bew QML file of Search from here
        QmlDocument *qml = QmlDocument::create("asset:///SearchResults.qml").parent(
                this);
        qml->setContextProperty("peoplefinder", this);
    
        Page *mypage = qml->createRootObject();
        qml->setParent(mypage);
        qDebug() << "PeopleFinder::PeopleFinder::onSearchClicked::\t s444444";
    
        // Retrieve the activity indicator from QML so that we can start
        // and stop it from C++
    //  mActivityIndicator = mypage->findChild("myIndicator");
    
        // Retrieve the list so we can set the data model on it once
        // we retrieve it
        mListView = mypage->findChild("resultlist");
    
        mNavigator->push(mypage);
    }
    

    Once the page loads in the QML it call the launch request providing c ++ file and once the
    query is completed under function is called with the data. I checked that data are downloaded properly

    void PeopleFinder::requestFinished(QNetworkReply* reply) {
        qDebug() << "PeopleFinder::PeopleFinder::requestFinished::\t"
                << "response received";
        // Check the network reply for errors
        if (reply->error() == QNetworkReply::NoError) {
    
            // Open the file and print an error if the file cannot be opened
            qDebug() << "PeopleFinder::PeopleFinder::requestFinished::\t"
                    << "No error";
    
            // Write to the file using the reply data and close the file
            QByteArray xml = reply->readAll();
            qDebug() << "Data: \n" << xml;
    
            // load the xml data
            XmlDataAccess xda;
            QVariant list = xda.load(xml, "ArrayOfPeople");
    
            qDebug() << "List:::\n" << list;
    
            GroupDataModel *datamodel = (GroupDataModel*)mListView->dataModel();
            // add the data to the model
            datamodel->clear();
            datamodel->insertList(list.value());
            datamodel->setSortingKeys(QStringList() << "givenName" << "sn");
            qDebug() << "PeopleFinder::PeopleFinder::requestFinished::\t"
                    << "Datamodel set size:: " << datamodel->size();
    
            // Set the new data model on the list and stop the activity indicator
    
        } else {
            qDebug() << "\n Problem with the network";
            qDebug() << "\n" << reply->errorString();
        }
    }
    

    But now, the real problem begins as in how to convert QByteArray data type of QVariantList which can be loaded into the datamodel
    I don't want to write the data to the XML file and then pass that as a list his will is very slow, once I move test environment to the production environment.

    Please help me solve this problem

    I got it to work using xml parsing with QXmlStreamReader

  • How to convert the Qbytearray into image in cascades

    Hi guys,.

    How can I convert a Qbytearray in image, so that I can show to imageView.Any the code examples will be useful

    Concerning

    Rakesh Shankar.P

    Thanks for your help, I was able to retrieve image

     QImage swapped;
         qDebug()<<"data"<setImage(image);     container->add(testImage);
    

    Concerning

    Rakesh Shankar.P

  • bt_gatt_write_value_noresp HowTo convert ascii uint8_t string *.

    my C knowledge is very poor and so I have a question.

    use case:

    Crystal APP

    connected to a custom equipment

    Find services and connect to services: OK

    Characteristics of the found Services

    Record the reading for the notification Service: OK - all notifications are coming through

    now, I also have to WRITE a feature using

    int bt_gatt_write_value_noresp(int instance, uint16_t handle, uint16_t offset, const uint8_t *data, int size)
    

    This is the command that I want to write to the device as a String:

    "$HTMEA, 1, 7 * 7F\r\n".

    How to convert this string ascii uint8_t *?

    and what is the length (size)?

    using the. toAscii() I take a ByteArray and there is a. constData() which gives me a char *- but it does not help.

    looked at BT THE Primer, examples of applications and blogs, but did not find an example where a QString will be converted and sent to the device.

    the other way back to recall notice where the uint8_t * was transformed into a QString, I found in the sample application and this heart rate monitor market.

    thx for help

    overdraft.

    First, I had to get the hexadecimal value of my request chain.

    QString theRequest = "$HTMEA,1,,7*7F\r\n";const int characteristicLen = theRequest.size();uint8_t *characteristicBuffer = (uint8_t *) alloca(characteristicLen + 1);QString theRequestAsHex = theRequest.toAscii().toHex();
    

    so I found some utilities BT THE sample applications to help me turn this into uint8_t *.

    Utilities::hexToIntArray(theRequestAsHex, characteristicBuffer);
    

    The following methods of the utility:

    const QString Utilities::HEX_CHARS = QString("0123456789ABCDEF");
    uint8_t Utilities::hexToInt(QChar c1, QChar c2) {
        c1 = c1.toUpper();
        c2 = c2.toUpper();
        uint8_t result = 0;
        result = HEX_CHARS.indexOf(c1) * 16;
        result = result + HEX_CHARS.indexOf(c2);
        return result;
    }
    void Utilities::hexToIntArray(QString hex_string, uint8_t* output) {
        const size_t numdigits = hex_string.length() / 2;
        for (size_t i = 0; i != numdigits; ++i) {
            output[i] = hexToInt(hex_string.at(2 * i), hex_string.at(2 * i + 1));
        }
    }
    

    Thanks to the old guys BlackBerry John Murray and Martin Woolley, for all their great stuff on BT, BTLE and NFC.

  • HowTo? convert virtual machines Hyper-V in ESX 4.0

    Hi, maybe posted a million times BUT:

    I have yet to convert a virtual Hyper-V for ESX 4 computer.

    Guests (W2K3, W2K8, W2K8R2)

    I tried

    -WinImage

    -Starwind

    -MS VMM

    -Vmware converter coldclone

    -Vmware converter online

    and again: If a VMDK of OS in ESX VM file does not start a VDISK or even knows that there is a file system.

    -What did I do wrong?

    Thank you very much...

    Stefan

    V2V 2008 R2 de HyperV for VMware is pretty easy - you should not even VMware Converter...

    read my notes here

    http://sanbarrow.com/p2v2008r2.html

    ___________________________________

    VMX-settings- Workstation FAQ -[MOA-liveCD | http://sanbarrow.com/moa241.html]- VM-infirmary

  • HOWTO convert a 2 GB piece ito a growable disk single?

    Dear community,

    How can I convert a capable drive to grow into pieces of 2 GB breed only a drive capable?

    I already tried the following:

    VMware-vdiskmanager - r ' vm/olddisk.vmdk' t 0 vm/newdisk.vmdk

    But when I try this command, I get the following error:

    Disc creation ' vm/newdisk.vmdk.

    Cannot convert the disc: the parent of this virtual disk could not be opened (0x1700003e8c).

    How I can solve this, I use Windows 7 x 64 with vmware workstation 7.01.

    Thank you in advance.

    Richard

    try something like this

    vmware-vdiskmanager -r "c:\vm\olddisk.vmdk" -t 0 "c:\vm\newdisk.vmdk"
    

    ___________________________________

    VMX-settings- Workstation FAQ -[MOA-liveCD | http://sanbarrow.com/moa241.html]- VM-infirmary

  • CANNOT convert webpage to PDF

    Something caused my Acrobat converter stop processing the conversion of web pages in IE8, which should convert to PDF format. It starts a second, and then a pop up comes up saying "couldn't access acrobats Web access facility.  Acrobat may be busy or waiting for the entry' I add we activated.  What else is my problem?

    Try this:

    Restore point:

    http://www.howtogeek.com/HOWTO/Windows-Vista/using-Windows-Vista-system-restore/

    Do Safe Mode system restore, if it is impossible to do in Normal Mode.

    Try typing F8 at startup and in the list of Boot selections, select Mode safe using ARROW top to go there > and then press ENTER.

    Try a restore of the system once, to choose a Restore Point prior to your problem...

    Click Start > programs > Accessories > system tools > system restore > choose another time > next > etc.

    http://www.windowsvistauserguide.com/system_restore.htm

    Read the above for a very good graph shows how backward more than 5 days in the System Restore Points by checking the correct box.

    See you soon.

    Mick Murphy - Microsoft partner

  • How to record the QByteArray Image?

    Hello

    How to save picture JPG of QByteArray to BB10 device?

    Thanks a lot before

    QByteArray table;<--- this="" has="" the="" image="" data="" in="" byte="">

    QImage image = QImage::fromData (table, "BMP"); original was bmp for me, I convert it to jpeg format below

    QFile outFile("shared/photos/temp1.jpeg");

    outFile.open (QIODevice::WriteOnly);
    image. Save (& outFile, "JPEG");

    Let me know if it works, I just finished finished written an application that allows a user to sketch and doodle photos with their fingers and it had save function to debug it.

  • How to convert the &lt; Contact &gt; QLIST Qstring

    Hello

    I would like to send my contacts from the device to the server using the Soap web service. but the method which who sent the item on the server takes the QString parameter and the contacts which I am retriving are type QLIST then please suggest me a method that converts the QList QString.

    Help, please...

    QString has a constructor that accepts a QByteArray.

  • QByteArray fromHex error.

    Hi all

    I'm usin the QByteArray fromHex function, it works for small chains, but fails to larger.

    any body facing a similar question?

    Kind regards.

    I see only a 20 M byte array, converted into a hexagon of 40 M work of encoding...

    #include 
    #include 
    #include 
    
    int main(int argc, char *argv[]) {
        QByteArray test;
        for (int i = 0; i < 20000000; ++i) {
            test.append(rand());
        }
        QByteArray asHex(test.toHex());
        QString useEvenMoreMemory(asHex);
        QByteArray back(QByteArray::fromHex(useEvenMoreMemory.toLocal8Bit()));
    
        if (test.length() != back.length()) {
            qDebug() << "Size problems...";
        } else {
            bool good = true;
            qDebug() << "Length match";
            for (int i = 0; good && i < test.length(); ++i) {
                if (test[i] != back[i]) {
                    good = false;
                }
            }
    
            qDebug() << "Good" << good;
        }
    
        return 0;
    }
    
  • QByteArray in Json

    How to convert a QByteArray from a JSON response network?

    Check with the function below:

    void GridSample::requestFinished( QNetworkReply * reply){
        QVariantMap dataName;
                if (reply) {
                    if (reply->error() == QNetworkReply::NoError) {
                        const int available = reply->bytesAvailable();
                        if (available > 0) {
                            const QByteArray buffer(reply->readAll());
    
                            bb::data::JsonDataAccess ja;
                            const QVariant jsonva = ja.loadFromBuffer(buffer);
                            const QVariantMap jsonreply = jsonva.toMap();
                            QVariantList data = jsonreply["photos"].toList();
                            foreach(QVariant v, data){
                                dataName["text"]=v.toMap().value("created_at").toString();
                                myGroupModel->insert(dataName);
                            }
                        }
                    } else {
    
                    }
                    reply->deleteLater();
                }
    }
    
  • How to scan a hard copy in pdf format I can convert in word to change?

    I have a HP deskjet 3050 a and my operating system is Windows 7, how to scan a hard copy in pdf format I can convert in word to change?

    Hello
    The software provided for your device does not include OCR functionality

    You can use a solution of OCR 3rd party to analyze as editable text.

    If you have Microsoft Office suite, there is a good chance of the suite to provide this type of functionality:

    Office 2007 or 2010:
    http://www.howtogeek.com/HOWTO/14595/OCR-anything-with-OneNote-2007-and-2010/

    Office 2003:
    http://agsci.PSU.edu/it/how-to/perform-OCR-with-Microsoft-Office-2003-document-imaging

    Kind regards
    Shlomi

  • What is the fastest way to convert VMWare workstation VM of ESXi?

    Hello

    Was curious to know what is the quickest way to convert a VMWare workstation VM to a VM compatible ESXi. Is the method of standalone converter VMWare at the following ADDRESS of the faster method:

    http://www.networkinghowtos.com/HOWTO/convert-virtual-machine-VMware-Workstation-ESXi-vSphere/

    Or is the method below faster? The method below mentions converter standalone is required for Workstation 8 VM but did not mention if it is needed for Workstation 8 AND HIGHER VM (ie: 9 and 10 workstation).

    http://KB.VMware.com/selfservice/microsites/search.do?language=en_US & cmd = displayKC & externalId = 1012258

    My ultimate goal is to export on a USB key and then import on the ESXi instead of convert and copy it to the network server. I'm exporting to my 3 TB USB would be faster than the copy of the virtual machine on the network. Thoughts?

    I think the second is the best option VMware KB: export of VMS in VMware Workstation to ESX/ESXi

    As you can see you can export the VM and after import on the EXS (do not use personalization)

    But uf you have Vmware Workstation 8 or higher, you can connect to the ESX Server and move the machine. If you are in the same local network and do it at a time of low workload, it would be the best option.

Maybe you are looking for