标签:
1、新建Muilti Device C++ Builder工程,在 .h 中加入2个头文件:
#include <FMX.PlatForm.hpp>
#include<FMX.PhoneDialer.hpp>
2、加入private声明变量:_di_IFMXPhoneDialerService phoneDialerService;(无需加*,但类型是指针)
__published声明方法: void __fastcall MyOnCallStateChanged (const UnicodeString aCallID,const TCallState aCallState);
3、加入控件来显示,此时 Edit 要作为拨号键盘使用,因此要设置
KeyboardType = NumberPad
ReturnKeyType = Go
KillFocusByReturn = True
4、在.cpp中,为2个按钮写入代码:
//获取运营商信息,在Label1和Label2中显示出来
void __fastcall TForm3::Button1Click(TObject *Sender)
{
this->Label1->Text=phoneDialerService->GetCarrier()->GetCarrierName();
this->Label2->Text=phoneDialerService->GetCarrier()->GetIsoCountryCode();
}
//按照Edit中的号码拨号
void __fastcall TForm3::Button2Click(TObject *Sender)
{
phoneDialerService->Call(this->Edit1->Text);
}
5、为新方法MyOnCallStateChanged写入代码:
void __fastcall TForm3::MyOnCallStateChanged(const UnicodeString aCallID,
const TCallState aCallState)
{
switch(aCallState){
case TCallState::None:
Label3->Text=""+aCallID;
break;
case TCallState::Connected:
Label3->Text=L"有来电"+aCallID;
break;
case TCallState::Dialing:
Label3->Text=L"正在拨号"+aCallID;
break;
case TCallState::Disconnected:
Label3->Text=L"断开"+aCallID;
break;
}
}
6、点击Form在Events中的OnCreate事件,写入代码:
void __fastcall TForm3::FormCreate(TObject *Sender)
{
phoneDialerService=TPlatformServices::Current->GetPlatformService(__uuidof(IFMXPhoneDialerService));
phoneDialerService->OnCallStateChanged=MyOnCallStateChanged;
}
7、在手机上安装后,在拨号键盘中输入电话号码,如10086,点击拨号即可。点击2个按钮,头两个Label的内容可显示运营商的名称及代码。
RAD Studio XE8 在APP里实现手机的拨号功能
标签:
原文地址:http://www.cnblogs.com/aceview789/p/4775386.html