博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Android实例-使用电话拨号器在移动设备上(官方)(XE8+小米2)
阅读量:5836 次
发布时间:2019-06-18

本文共 6129 字,大约阅读时间需要 20 分钟。

源文地址:

http://docwiki.embarcadero.com/RADStudio/XE5/en/Mobile_Tutorial:_Using_the_Phone_Dialer_on_Mobile_Devices_(iOS_and_Android)

 

1.获取运营商、国家代码

1 unit Unit1; 2  3 interface 4  5 uses 6   System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants, 7   FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, FMX.Controls.Presentation, 8   FMX.StdCtrls, FMX.Edit, 9   FMX.Platform,//需要引入10   FMX.PhoneDialer;//需要引入11 12 type13   TForm1 = class(TForm)14     Button1: TButton;15     lblCarrierName: TEdit;16     lblISOCountryCode: TEdit;17     Button2: TButton;18     edtTelephoneNumber: TEdit;19     lblCallState: TEdit;20     Label1: TLabel;21     Label2: TLabel;22     Label3: TLabel;23     procedure Button1Click(Sender: TObject);24     procedure Button2Click(Sender: TObject);25   private26     //电话服务27     PhoneDialerService: IFMXPhoneDialerService;28     {
Private declarations }29 public30 //需要覆盖31 constructor Create(AOwner: TComponent); override;32 {
Public declarations }33 end;34 35 var36 Form1: TForm1;37 38 implementation39 40 {
$R *.fmx}41 {
$R *.NmXhdpiPh.fmx ANDROID}42 43 {
TForm1 }44 45 //获取电话服务46 constructor TForm1.Create(AOwner: TComponent);47 begin48 inherited Create(AOwner);49 TPlatformServices.Current.SupportsPlatformService(IFMXPhoneDialerService, IInterface(PhoneDialerService));50 end;51 52 //获取运营商53 procedure TForm1.Button1Click(Sender: TObject);54 begin55 {
test whether the PhoneDialer services are supported on your device }56 if Assigned(PhoneDialerService) then57 begin58 {
if yes, then update the labels with the retrieved information }59 lblCarrierName.Text := 'Carrier Name: ' + PhoneDialerService.GetCarrier.GetCarrierName;60 lblISOCountryCode.Text := 'ISO Country Code: ' + PhoneDialerService.GetCarrier.GetIsoCountryCode;61 end;62 end;63 64 end.

 

2.实现打电话功能

1 unit Unit1; 2  3 interface 4  5 uses 6   System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants, 7   FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, FMX.Controls.Presentation, 8   FMX.StdCtrls, FMX.Edit, 9   FMX.Platform,//需要引入10   FMX.PhoneDialer;//需要引入11 12 type13   TForm1 = class(TForm)14     Button1: TButton;15     lblCarrierName: TEdit;16     lblISOCountryCode: TEdit;17     Button2: TButton;18     edtTelephoneNumber: TEdit;19     lblCallState: TEdit;20     Label1: TLabel;21     Label2: TLabel;22     Label3: TLabel;23     procedure Button1Click(Sender: TObject);24     procedure Button2Click(Sender: TObject);25   private26     //电话服务27     PhoneDialerService: IFMXPhoneDialerService;28     {
Private declarations }29 public30 //需要覆盖31 constructor Create(AOwner: TComponent); override;32 {
Public declarations }33 end;34 35 var36 Form1: TForm1;37 38 implementation39 40 {
$R *.fmx}41 {
$R *.NmXhdpiPh.fmx ANDROID}42 43 {
TForm1 }44 //获取电话服务45 constructor TForm1.Create(AOwner: TComponent);46 begin47 inherited Create(AOwner);48 TPlatformServices.Current.SupportsPlatformService(IFMXPhoneDialerService, IInterface(PhoneDialerService));49 end;50 51 //打电话功能52 procedure TForm1.Button2Click(Sender: TObject);53 begin54 {
test whether the PhoneDialer services are supported on your device }55 if Assigned(PhoneDialerService) then56 begin57 {
if the Telephone Number is entered in the edit box then make the call, else58 display an error message }59 if edtTelephoneNumber.Text <> '' then60 PhoneDialerService.Call(edtTelephoneNumber.Text)61 else62 begin63 ShowMessage('Please type-in a telephone number.');64 edtTelephoneNumber.SetFocus;65 end;66 end;67 end;68 69 end.

 

3.检测呼叫状态的变化

1 unit Unit1; 2  3 interface 4  5 uses 6   System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants, 7   FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, FMX.Controls.Presentation, 8   FMX.StdCtrls, FMX.Edit, 9   FMX.Platform,//需要引入10   FMX.PhoneDialer;//需要引入11 12 type13   TForm1 = class(TForm)14     Button1: TButton;15     lblCarrierName: TEdit;16     lblISOCountryCode: TEdit;17     Button2: TButton;18     edtTelephoneNumber: TEdit;19     lblCallState: TEdit;20     Label1: TLabel;21     Label2: TLabel;22     Label3: TLabel;23     procedure Button1Click(Sender: TObject);24     procedure Button2Click(Sender: TObject);25   private26     //电话服务27     PhoneDialerService: IFMXPhoneDialerService;28     //定义方法29     procedure MyOnCallStateChanged(const ACallID: String; const ACallState: TCallState);30     {
Private declarations }31 public32 //需要覆盖33 constructor Create(AOwner: TComponent); override;34 {
Public declarations }35 end;36 37 var38 Form1: TForm1;39 40 implementation41 42 {
$R *.fmx}43 {
$R *.NmXhdpiPh.fmx ANDROID}44 45 {
TForm1 }46 47 //获取电话服务48 constructor TForm1.Create(AOwner: TComponent);49 begin50 inherited Create(AOwner);51 TPlatformServices.Current.SupportsPlatformService(IFMXPhoneDialerService, IInterface(PhoneDialerService));52 if Assigned(PhoneDialerService) then53 PhoneDialerService.OnCallStateChanged := MyOnCallStateChanged;54 end;55 56 //检测呼叫状态的变化57 procedure TForm1.MyOnCallStateChanged(const ACallID: String;58 const ACallState: TCallState);59 var outText: String;60 begin61 case ACallState of62 FMX.PhoneDialer.TCallState.None: outText := 'No calls';63 FMX.PhoneDialer.TCallState.Connected: outText := 'Connected';64 FMX.PhoneDialer.TCallState.Incoming: outText := 'Incoming call';65 FMX.PhoneDialer.TCallState.Dialing: outText := 'Dialing';66 FMX.PhoneDialer.TCallState.Disconnected: outText := 'Disconnected';67 end;68 lblCallState.Text := outText;69 end;70 71 end.

PS:

IFMXPhoneDialerService 接口提供了 OnCallStateChanged 事件,允许您处理呼叫状态的变化。 的 TCallState 枚举描述可能的电话状态。

下面的表描述的物品 TCallState 枚举(为每个平台支持的州是标有“+”)。 

描述 iOS 安卓
csNone 没有呼叫状态。 + - - - - - -
csConnected 电话调用者与被调用方。 + +
csIncoming 传入的电话。 + +
csDialing 手机在拨号状态。 + - - - - - -
csDisconnected 调用断开连接。 +

 

 

转载于:https://www.cnblogs.com/FKdelphi/p/4721610.html

你可能感兴趣的文章
BZOJ1997:[HNOI2010]PLANAR——题解
查看>>
HTML5新手入门指南
查看>>
opennebula 开发记录
查看>>
sql 内联,左联,右联,全联
查看>>
C++关于字符串的处理
查看>>
Breaking parallel loops in .NET C# using the Stop method z
查看>>
修改故障转移群集心跳时间
查看>>
[轉]redis;mongodb;memcache三者的性能比較
查看>>
让你的WPF程序在Win7下呈现Win8风格主题
查看>>
802.11 学习笔记
查看>>
Leetcode-Database-176-Second Highest Salary-Easy(转)
查看>>
构建Docker Compose服务堆栈
查看>>
Hadoop生态圈-Kafka常用命令总结
查看>>
如何基于Redis Replication设计并实现Redis-replicator?
查看>>
浮点数内存如何存储的
查看>>
贪吃蛇
查看>>
EventSystem
查看>>
用WINSOCK API实现同步非阻塞方式的网络通讯
查看>>
玩一玩博客,嘿嘿
查看>>
Ubuntu设置python3为默认版本
查看>>