This sample application demonstrates how to send a SMS to a given cellphone specified by mobile number.
1. Get the PhoneFactory and PhoneManager instances
auto &phoneFactory = PhoneFactory::getInstance();
auto phoneManager = phoneFactory.getPhoneManager();
2. Check if telephony subsystem is ready
bool subSystemsStatus = phoneManager->isSubsystemReady();
2.1 If telephony subsystem is not ready, wait for it to be ready
Telephony subsystems is to make sure that device is ready for services like Phone, SMS and others. if subsystems were not ready, wait for unconditionally.
if(!subSystemsStatus) {
std::future<bool> f = phoneManager->onSubsystemReady();
subSystemsStatus = f.get();
}
3. Instantiate SMS sent and delivery callback
auto smsSentCb = std::make_shared<SmsCallback>();
auto smsDeliveryCb = std::make_shared<SmsDeliveryCallback>();
3.1 Implement ICommandResponseCallback interface to know SMS sent and delivery status
class SmsCallback : public ICommandResponseCallback {
public:
void commandResponse(ErrorCode error) override;
};
void SmsCallback::commandResponse(ErrorCode error) {
std::cout << "onSmsSent callback" << std::endl;
}
class SmsDeliveryCallback : public ICommandResponseCallback {
public:
void commandResponse(ErrorCode error) override;
};
void SmsDeliveryCallback::commandResponse(ErrorCode error) {
std::cout << "SMS Delivery callback" << std::endl;
}
4. Get default SMS manager instance
std::shared_ptr<ISmsManager> smsManager = phoneFactory.getSmsManager();
5. Send an SMS using ISmsManager by passing the text and receiver number along with required callback
if(smsManager) {
std::string receiverAddress("+18989531755");
std::string message("TEST message");
smsManager->sendSms(message, receiverAddress, smsSentCb, smsDeliveryCb);
}
Now, we will receive resonses in callbacks defined at step 3 (smsSentCb, smsDeliveryCb).