Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Native Development

Reply
Highlighted
New Developer
Posts: 40
Registered: ‎01-24-2014
My Device: Q5
My Carrier: WIFI

Headless Application Question

Hi all.

 

When i'm using headless i think do more without open Ul part like another platforms but that not true.

 

I have worked full application but has reached a point when the headless, surprised that you can not do anything there specific things.

 

So I tried to work some tricks but did not work and can not make the application without headless because it will be useless.

 

What I want to do is to update the data and then change title notifications.

 

I think it can be done in two ways:

 

1- Use HTTP connections and reply can it change title notifications?

 

2- I can do local html page and update every day then send data and received via onMessageReceived but need reload page to refresh data can do it like this in headless?

 

There are applications, change the wallpaper in headless! Is this official manner?

 

 

Please help me I've worked on the application for almost two months.


Cheers,
Slosh.

Developer
Posts: 33
Registered: ‎08-28-2013
My Device: non-BlackBerry user
My Carrier: TURKCELL

Re: Headless Application Question

You can send requests, post or get data etc. within headless part of the app. Go to your .pro file (of your headless part) and add this -> QT += network. Then, on top of your service.cpp file add these ->
#include <QtNetwork/QNetworkAccessManager>
#include <QtNetwork/QNetworkReply>
#include <QtNetwork/QNetworkRequest>

 

By adding the second part, you have added your libraries. It may even compile without any problem but during run-time you are going to have exceptions. This is why we add the first part. By adding QT += network you now linked those libraries appropriately. Use these data types, which are QNetworkAccessManager, QNetworkReply and QNetworkRequest, to make your request and retrieve your data. After you got your data be sure that  you change it to appropriate format. For example:

void Service::replyTaken() {
    QNetworkReply* reply = qobject_cast<QNetworkReply*>(sender());
    const QByteArray buffer(reply->readAll());
    QString response = QString::fromUtf8(buffer);
}

 The code above will help you to convert the data you will receive into QString since the reply will be in QByteArray format. Don't forget to connect this slot to your signal where you make your request. What I mean is when the request is done and reply is retrieved, the code should now run replyTaken() method (basic signal-slot process). In the end you can modify your notification according to your data and trigger it.

Notification* notification = new Notification(this);
notification->setTitle("Your modified title according to response");
notification->setBody("Your modified body according to response");
notification->notify();

 Hope I could help. 

New Developer
Posts: 40
Registered: ‎01-24-2014
My Device: Q5
My Carrier: WIFI

Re: Headless Application Question

@moltres

 

Tahnks.


Really I don't know how to use QNetworkRequest and i'm using QFile to load the json to get data in list.

 

So I have some questions:

 

1- can request local file? "Like use html and in the html javascript using api i'm using this and run but can request?"
2- Do I need to use DateTimePicker to run replyTaken or this is automatic?

Developer
Posts: 33
Registered: ‎08-28-2013
My Device: non-BlackBerry user
My Carrier: TURKCELL

Re: Headless Application Question

Hey again,

I will start from your 2nd question. replyTaken method is of course not automatic. As I indicated before you have to create signal-slot connection first. Look at the code sample below:

QNetworkRequest request= QNetworkRequest();
request.setUrl(QUrl("yourUri"));
QNetworkAccessManager* m_pNetAccessMngr = new QNetworkAccessManager(this);
QNetworkReply* networkReply = m_pNetAccessMngr->get(request);
connect(networkReply, SIGNAL(finished()), this, SLOT(replyTaken()));

 This sample code will help you to make an asynchronous request and get response. Before copying and pasting it, I suggest you to understand it first. request is the request you are going to do. m_pNetAccessMngr is the manager that handles your requests. networkReply is the response you get from your requests. Last expression was the creating connection thing I have told you before. Your signal is getting response. Your slot is replyTaken method where you are going to process the response.

connect(networkReply, SIGNAL(finished()), this, SLOT(replyTaken()));

This experssion means that when "networkReply is finished" (meaning you got your response) "call this object's replyTaken method" (meaning run this pre-determined code part). 

 

For your first question, you can use the entire same logic, but instead of making request to web, write necessary code to access your local file. I have never dealt with QFile therefore I don't have any code sample.


The whole code will enable you to send a request to web, get your response & process it within headless part of the app.  I am using same code for getting JSON response from the API that I created.

 

Hope it helps.

---
Please accept my answer as solution if you find it helpful and it solved your problem. Thank you Smiley Happy

New Developer
Posts: 40
Registered: ‎01-24-2014
My Device: Q5
My Carrier: WIFI

Re: Headless Application Question

[ Edited ]

@moltres

 

Thank you very much.

 

I knew replyTaken not automatic i mean when use it like void ApplicationUI:: POST then use connect(networkReply, SIGNAL(finished()), this, SLOT(replyTaken())); how to make signal to POST to run in headless part? "like use QTimer"

 

Well I did not use QNetworkRequest so how receives the reply, for example, when using HTML?

New Developer
Posts: 40
Registered: ‎01-24-2014
My Device: Q5
My Carrier: WIFI

Re: Headless Application Question

Up