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
New Contributor
rockar06
Posts: 6
Registered: ‎10-27-2013
My Device: BBZ10
Accepted Solution

How can I end a call?

[ Edited ]

Hi all!

 

I've tried to use the next code to end a call:

 

import bb.cascades 1.0
import bb.system 1.0

Page {
    Container {
        layout: DockLayout {
        }
        verticalAlignment: VerticalAlignment.Center
        horizontalAlignment: HorizontalAlignment.Center
        
        Button {
            id: callButton
            text: "End Call"
            
            onClicked: {
                phone.endCall("5555555555")
            }
            
        }
        
    }
    attachedObjects: [
        Phone {
            id: phone
        }
    ]
}

 

But it doesn't work.

 

What is missing?

 

I don't know if I need ti put the number of the incoming call. 

 

Thanks for your help!

 

Regards!

Please use plain text.
Retired
mwoolley
Posts: 571
Registered: ‎06-25-2010
My Device: Z10

Re: How can I end a call?

Hi

 

no, it's not the phone number that you need to supply. It's the "Call ID" which is a unique session parameter for  a specfic call. See https://developer.blackberry.com/native/reference/cascades/bb__system__phone__phone.html#function-en...

 

Regards

 

Martin

--------------------------------------------------------------------------------------------
Feel free to press the like button on the right side if you liked my attempts to help :-)
And please mark posts as solved if you think I found the solution or set you on its path. Thanks!
Follow me on Twitter: @mdwrim
Please use plain text.
Contributor
danywarner
Posts: 38
Registered: ‎09-06-2013
My Device: BlackBerry Z10

Re: How can I end a call?

where is that ID supposed to be found/gotten from?



_______________________________________________________
If you've been helped click on Like Button, if you've been saved download the app.

Developer of Easy Memes
Please use plain text.
Retired
mwoolley
Posts: 571
Registered: ‎06-25-2010
My Device: Z10

Re: How can I end a call?

I guess it depends how the call was initiated. If you initiated the call through a Phone object, then you have a Call object and this gives you the call ID:

 

https://developer.blackberry.com/native/reference/cascades/bb__system__phone__call.html

 

I think this is the scenario for which end call is designed.

--------------------------------------------------------------------------------------------
Feel free to press the like button on the right side if you liked my attempts to help :-)
And please mark posts as solved if you think I found the solution or set you on its path. Thanks!
Follow me on Twitter: @mdwrim
Please use plain text.
New Contributor
rockar06
Posts: 6
Registered: ‎10-27-2013
My Device: BBZ10

Re: How can I end a call?

I find difficult to understand the "callID", Is it possible if you could show me an example code? 

I would appreciate your help! :Helpsmilie:

 

Regards

Please use plain text.
Retired
mwoolley
Posts: 571
Registered: ‎06-25-2010
My Device: Z10

Re: How can I end a call?

Here's a full, working application for you to play with :-)

 

main.qml:

import bb.cascades 1.2

Page {
    Container {
        Label {
            // Localized text with the dynamic translation and locale updates support
            text: qsTr("Phone Test") + Retranslate.onLocaleOrLanguageChanged
            textStyle.base: SystemDefaults.TextStyles.BigText
        }
        Container {
            layout: StackLayout {
                orientation: LayoutOrientation.LeftToRight
            }
            TextField {
                id: txf_phone_number
                inputMode: TextFieldInputMode.PhoneNumber
                input.flags: TextInputFlag.AutoCapitalizationOff | TextInputFlag.AutoCorrectionOff | TextInputFlag.AutoPeriodOff | TextInputFlag.PredictionOff | TextInputFlag.SpellCheckOff
            }
            Button {
                text: "Make Call"
                onClicked: {
                    app.makeCall(txf_phone_number.text);
                }
            }
        }
        Button {
            text: "End Call"
            onClicked: {
                app.endCall();
            }
        }
    }
}

 applicationui.hpp:

#ifndef ApplicationUI_HPP_
#define ApplicationUI_HPP_

#include <QObject>
#include <bb/system/phone/Phone>
#include <bb/system/phone/Call>

namespace bb
{
    namespace cascades
    {
        class Application;
        class LocaleHandler;
    }
}

class QTranslator;

/*!
 * @brief Application object
 *
 *
 */

class ApplicationUI : public QObject
{
    Q_OBJECT
public:
    ApplicationUI(bb::cascades::Application *app);
    virtual ~ApplicationUI() { }

    Q_INVOKABLE void makeCall(QString msisdn);
    Q_INVOKABLE void endCall();

    bb::system::phone::Phone* _phone;
    int _call_id;

private slots:
    void onSystemLanguageChanged();
    void onCallUpdated (const bb::system::phone::Call& call );

private:
    QTranslator* m_pTranslator;
    bb::cascades::LocaleHandler* m_pLocaleHandler;
};

#endif /* ApplicationUI_HPP_ */

 applicationui.cpp:

#include "applicationui.hpp"

#include <bb/cascades/Application>
#include <bb/cascades/QmlDocument>
#include <bb/cascades/AbstractPane>
#include <bb/cascades/LocaleHandler>

using namespace bb::cascades;
using namespace bb::system::phone;

ApplicationUI::ApplicationUI(bb::cascades::Application *app) :
        QObject(app)
, _phone(new bb::system::phone::Phone())
{
    // prepare the localization
    m_pTranslator = new QTranslator(this);
    m_pLocaleHandler = new LocaleHandler(this);
    if(!QObject::connect(m_pLocaleHandler, SIGNAL(systemLanguageChanged()), this, SLOT(onSystemLanguageChanged()))) {
        // This is an abnormal situation! Something went wrong!
        // Add own code to recover here
        qWarning() << "Recovering from a failed connect()";
    }
    // initial load
    onSystemLanguageChanged();

    // Create scene document from main.qml asset, the parent is set
    // to ensure the document gets destroyed properly at shut down.
    QmlDocument *qml = QmlDocument::create("asset:///main.qml").parent(this);

    qml->setContextProperty("app", this);
    QObject::connect(_phone, SIGNAL(callUpdated(const bb::system::phone::Call&)),
    		this, SLOT(onCallUpdated(const bb::system::phone::Call&)));
    // Create root object for the UI
    AbstractPane *root = qml->createRootObject<AbstractPane>();

    // Set created root object as the application scene
    app->setScene(root);
}

void ApplicationUI::onSystemLanguageChanged()
{
    QCoreApplication::instance()->removeTranslator(m_pTranslator);
    // Initiate, load and install the application translation files.
    QString locale_string = QLocale().name();
    QString file_name = QString("PhoneTest_%1").arg(locale_string);
    if (m_pTranslator->load(file_name, "app/native/qm")) {
        QCoreApplication::instance()->installTranslator(m_pTranslator);
    }
}

void ApplicationUI::makeCall(QString msisdn) {
	qDebug() << "XXXX makeCall: " << msisdn;

	// reset call_id
	_call_id = -1;
	_phone->initiateCellularCall(msisdn);

}

void ApplicationUI::endCall() {
	qDebug() << "XXXX endCall";
	if (_call_id != -1) {
		_phone->endCall(_call_id);
	}
}

void ApplicationUI::onCallUpdated(const bb::system::phone::Call& call ) {
	qDebug() << "XXXX onCallUpdated";
	_call_id = call.callId();
	qDebug() << "XXXX onCallUpdated - call_id=" << _call_id;
}

 Permissions in bar-descriptor.xml:

    <permission>control_phone</permission>
    <permission>access_phone</permission>

 PhoneTest.pro:

APP_NAME = PhoneTest

CONFIG += qt warn_on cascades10

LIBS += -lbbsystem

include(config.pri)

 

 

--------------------------------------------------------------------------------------------
Feel free to press the like button on the right side if you liked my attempts to help :-)
And please mark posts as solved if you think I found the solution or set you on its path. Thanks!
Follow me on Twitter: @mdwrim
Please use plain text.
New Contributor
rockar06
Posts: 6
Registered: ‎10-27-2013
My Device: BBZ10

Re: How can I end a call?

Thank you very much man! I works! I've tried for a long time unsuccessfully, but now it's different.

 

Thanks again! :Clap:

Please use plain text.
Retired
mwoolley
Posts: 571
Registered: ‎06-25-2010
My Device: Z10

Re: How can I end a call?

It's a pleasure :-)
--------------------------------------------------------------------------------------------
Feel free to press the like button on the right side if you liked my attempts to help :-)
And please mark posts as solved if you think I found the solution or set you on its path. Thanks!
Follow me on Twitter: @mdwrim
Please use plain text.
New Contributor
progressionsubramanian
Posts: 7
Registered: Friday
My Device: Q10

Re: How can I end a call?

Sir,

 

I get a error in main.cpp in the line as 

no matching function for call to 'ApplicationUI::ApplicationUI()'

 

ApplicationUI appui;  

 

I use Monmentics IDE and I am new to Blackberry programming

 

My main.cpp is 

#include "applicationui.hpp"

#include <bb/cascades/Application>

#include <QLocale>
#include <QTranslator>

#include <Qt/qdeclarativedebug.h>

using namespace bb::cascades;

Q_DECL_EXPORT int main(int argc, char **argv)
{
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();
}

Please use plain text.
New Contributor
progressionsubramanian
Posts: 7
Registered: Friday
My Device: Q10

Re: How can I end a call?

I solved it by doing the changes in main.cpp. Now it is working. Is it is possible to accept a incoming call.

 

 

 

Please use plain text.