O documento descreve a ferramenta AppTethering da Embarcadero Technologies, que permite controlar aplicativos Windows existentes a partir de aplicativos móveis. O AppTethering facilita a extensão de aplicativos para dispositivos móveis, permitindo a comunicação e transmissão de dados entre aplicativos VCL, FMX e móveis via Wi-Fi e Bluetooth.
Controle uma Aplicação Windows a partir de uma Aplicação Mobile com AppTethering
1. Embarcadero Technologies Copyright 2016
Controle uma Aplicação Windows
a partir de uma Aplicação Mobile com
AppTethering
Fernando Rizzato
Lead Software Consultant, Latin America
4. Embarcadero Technologies Copyright 2016
AppTethering
Expanda facilmente seus aplicativos existentes
do Windows para dispositivos móveis
Aplicações móveis complementares são a
resposta para os nossos clientes utilizando
Windows/VCL
Controle e interação com aplicativos do Windows
existentes e aplicativos móveis
Componentes simplificados de comunicação em
cada um dos lados
Por exemplo, um aplicativo do Google Glass pode
controlar os aspectos de um aplicativo do
Windows já existente
5. Embarcadero Technologies Copyright 2016
AT
AT
Your Desktop App
Your
Mobile
App
Your
Smartphone
App
AT
• Estenda Apps VCL e FMX
• Descoberta Automática de Devices
• Executar Eventos e Métodos Remotos
• Controle Apps Remotamente
• Envie e Receba Dados
• Suporte para Bluetooth e WiFi
AppTethering
6. Embarcadero Technologies Copyright 2016
AppTethering
Aplicativos VCL e FMX podem se
comunicar e transmitir dados sobre Wi-
Fi e Bluetooth
Open, baseado em componentes e
arquitetura plugável
Caso de Uso: Aplicação FM mobile como
"controle remoto" para aplicações VCL
existentes
7. Embarcadero Technologies Copyright 2016
TTetheringManager
Cada app tem um componente TTetheringManager
É o responsável pela função de Auto Discovery
Gerencia o pareamento e a conexão
Controla autenticação
8. Embarcadero Technologies Copyright 2016
TTetheringAppProfile
Cada app tem um ou mais TTetheringAppProfile
É o responsável por publicar ações para execução remota
Executa ações remotas que foram publicadas
Envia e recebe dados da app remota
9. Embarcadero Technologies Copyright 2016
Aplicações de AppTethering
Chamada bidirecional de ações
Permite criar uma segunda tela ”portátil”
Clicks e Eventos Remotos
Envio de Strings e Streams
Barcode scanner, reconhecimento de voz, entradas via
touch screen, captura de imagens ou dados de sensores
Expansão do alcance de sua app
12. Embarcadero Technologies Copyright 2016 12
OBRIGADO!
Perguntas?
Você pode me encontrar em:
@FernandoRizzato
fernando.rizzato@embarcadero.com
Siga-nos em
fb.com/DelphiBrasil
fb.com/EmbarcaderoBR
Notas do Editor
Execute remote actions, exchange data and use discovery service
App Tethering
Application tethering enables your apps to interact with other apps running either on the same machine or on a remote machine.
Using tethering, your applications can:
Discover other applications that support tethering running on the same device or on other connected devices.
Share data between applications. Tethering allows sharing both strings and streams, and you can use streams to implement support for any other data structure.
Execute actions remotely. An application can publish actions using tethering; then a second application can invoke any of these actions remotely on the first application.
Tethering components: We follow the Bluetooth profile model: there is a main component, and then a profile that implements the functionality:
TTetheringManager: is the component that manages all basic operations: auto discovering and pairing with other remote managers.
TTetheringAppProfile implements the "Application Profile", a set of functionality that include executing remote actions, sharing resources and sending streams and strings between other paired profiles.
A manager needs to register a profile to start, so you need to drop a TTetheringManager component and a TTetheringAppProfile component in a form, and then link both components, filling the manager property in the profile component.
To find other tether applications in the network, your app needs to execute the method DiscoverManagers. You can set a timeout; the default timeout is 1500ms. When the timeout finishes, you receive the OnEndManagersDiscovery event, in which you receive a list of the discovered remote managers.
From this list of remote managers, you can choose the ones you want to pair with.
Example: Create a form with a button, a memo, a manager, and a profile.
uses
System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, FMX.StdCtrls,
FMX.Layouts, System.Generics.Collections, FMX.ListBox, IPPeerClient, IPPeerServer,
System.Tether.Manager, System.Tether.AppProfile, System.Tether.TCPProtocol;
type
TForm1 = class(TForm)
TetheringManager1: TTetheringManager;
TetheringAppProfile1: TTetheringAppProfile;
Button1: TButton;
Memo1: TMemo;
procedure TetheringManager1EndManagersDiscovery(const RemoteManagers: \
TList<System.Tether.Manager.TTetheringManagerInfo>);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.fmx}
procedure TForm3.Button1Click(Sender: TObject);
begin
TetheringManager1.DiscoverManagers;
end;
procedure TForm3.TetheringManager1EndManagersDiscovery(\
const RemoteManagers: TList<System.Tether.Manager.TTetheringManagerInfo>);
var
I: Integer;
begin
for I := 0 to RemoteManagers.Count - 1 do
Memo1.Lines.Add(RemoteManagers[I].ManagerText);
end;
In this example, you fill a memo with the text of all remote managers found.
When you want to make a manager private, you have to fill the password because another manager wants to pair, it needs to know this password to be able to pair.
To pair with a remote manager, you use the method PairManager(ARemoteManager). Then if the manager is protected by password, you receive an event OnRequestManagerPassword with the remote manager identifier and a password var to fill, so you need to provide the password to be able to pair:
If the password is wrong, then you get the event OnAuthErrorFromServer.
If the pairing is fine, then you receive OnPairedToServer along with the OnEndProfilesDiscovery event with all the profiles found in that manager.
On the remote side, the manager receives:
OnAuthErrorFromClient if the password is wrong.
OnPairedFromClient if the password is correct.
Profile
To use the basic functionality, you need to add a TTetheringProfileApp, and connect that profile to the existing manager. With this you can share data and actions with other profiles.
Next you add to the profile SharedActions and/or SharedResources:
Shared Actions: A shared action is a container that stores an action link to connect with an existing TAction, and has an ItemName that is used to track that action from all clients that want to execute the action. From the remote client, the action can be executed on demand.
Shared Resources: A shared resource is a container that stores a DataValue or a Stream, and its public name that is used in order to be referenced outside.
After you configure the sharing information in the profile that you are going to share, go to the client application that is going to use the shared profile. When that application is connected to the previously shared profile, you can instruct the client application profile to execute one remote action, by providing the actual discovered remote profile and the shared name of the action:
CommandApp.RunRemoteAction(CommandManager.RemoteProfiles[LbPlayers.ItemIndex], 'acPlayPause');
Execute remote actions, exchange data and use discovery service
App Tethering
Application tethering enables your apps to interact with other apps running either on the same machine or on a remote machine.
Using tethering, your applications can:
Discover other applications that support tethering running on the same device or on other connected devices.
Share data between applications. Tethering allows sharing both strings and streams, and you can use streams to implement support for any other data structure.
Execute actions remotely. An application can publish actions using tethering; then a second application can invoke any of these actions remotely on the first application.
Tethering components: We follow the Bluetooth profile model: there is a main component, and then a profile that implements the functionality:
TTetheringManager: is the component that manages all basic operations: auto discovering and pairing with other remote managers.
TTetheringAppProfile implements the "Application Profile", a set of functionality that include executing remote actions, sharing resources and sending streams and strings between other paired profiles.
A manager needs to register a profile to start, so you need to drop a TTetheringManager component and a TTetheringAppProfile component in a form, and then link both components, filling the manager property in the profile component.
To find other tether applications in the network, your app needs to execute the method DiscoverManagers. You can set a timeout; the default timeout is 1500ms. When the timeout finishes, you receive the OnEndManagersDiscovery event, in which you receive a list of the discovered remote managers.
From this list of remote managers, you can choose the ones you want to pair with.
Example: Create a form with a button, a memo, a manager, and a profile.
uses
System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, FMX.StdCtrls,
FMX.Layouts, System.Generics.Collections, FMX.ListBox, IPPeerClient, IPPeerServer,
System.Tether.Manager, System.Tether.AppProfile, System.Tether.TCPProtocol;
type
TForm1 = class(TForm)
TetheringManager1: TTetheringManager;
TetheringAppProfile1: TTetheringAppProfile;
Button1: TButton;
Memo1: TMemo;
procedure TetheringManager1EndManagersDiscovery(const RemoteManagers: \
TList<System.Tether.Manager.TTetheringManagerInfo>);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.fmx}
procedure TForm3.Button1Click(Sender: TObject);
begin
TetheringManager1.DiscoverManagers;
end;
procedure TForm3.TetheringManager1EndManagersDiscovery(\
const RemoteManagers: TList<System.Tether.Manager.TTetheringManagerInfo>);
var
I: Integer;
begin
for I := 0 to RemoteManagers.Count - 1 do
Memo1.Lines.Add(RemoteManagers[I].ManagerText);
end;
In this example, you fill a memo with the text of all remote managers found.
When you want to make a manager private, you have to fill the password because another manager wants to pair, it needs to know this password to be able to pair.
To pair with a remote manager, you use the method PairManager(ARemoteManager). Then if the manager is protected by password, you receive an event OnRequestManagerPassword with the remote manager identifier and a password var to fill, so you need to provide the password to be able to pair:
If the password is wrong, then you get the event OnAuthErrorFromServer.
If the pairing is fine, then you receive OnPairedToServer along with the OnEndProfilesDiscovery event with all the profiles found in that manager.
On the remote side, the manager receives:
OnAuthErrorFromClient if the password is wrong.
OnPairedFromClient if the password is correct.
Profile
To use the basic functionality, you need to add a TTetheringProfileApp, and connect that profile to the existing manager. With this you can share data and actions with other profiles.
Next you add to the profile SharedActions and/or SharedResources:
Shared Actions: A shared action is a container that stores an action link to connect with an existing TAction, and has an ItemName that is used to track that action from all clients that want to execute the action. From the remote client, the action can be executed on demand.
Shared Resources: A shared resource is a container that stores a DataValue or a Stream, and its public name that is used in order to be referenced outside.
After you configure the sharing information in the profile that you are going to share, go to the client application that is going to use the shared profile. When that application is connected to the previously shared profile, you can instruct the client application profile to execute one remote action, by providing the actual discovered remote profile and the shared name of the action:
CommandApp.RunRemoteAction(CommandManager.RemoteProfiles[LbPlayers.ItemIndex], 'acPlayPause');
Execute remote actions, exchange data and use discovery service
App Tethering
Application tethering enables your apps to interact with other apps running either on the same machine or on a remote machine.
Using tethering, your applications can:
Discover other applications that support tethering running on the same device or on other connected devices.
Share data between applications. Tethering allows sharing both strings and streams, and you can use streams to implement support for any other data structure.
Execute actions remotely. An application can publish actions using tethering; then a second application can invoke any of these actions remotely on the first application.
Tethering components: We follow the Bluetooth profile model: there is a main component, and then a profile that implements the functionality:
TTetheringManager: is the component that manages all basic operations: auto discovering and pairing with other remote managers.
TTetheringAppProfile implements the "Application Profile", a set of functionality that include executing remote actions, sharing resources and sending streams and strings between other paired profiles.
A manager needs to register a profile to start, so you need to drop a TTetheringManager component and a TTetheringAppProfile component in a form, and then link both components, filling the manager property in the profile component.
To find other tether applications in the network, your app needs to execute the method DiscoverManagers. You can set a timeout; the default timeout is 1500ms. When the timeout finishes, you receive the OnEndManagersDiscovery event, in which you receive a list of the discovered remote managers.
From this list of remote managers, you can choose the ones you want to pair with.
Example: Create a form with a button, a memo, a manager, and a profile.
uses
System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, FMX.StdCtrls,
FMX.Layouts, System.Generics.Collections, FMX.ListBox, IPPeerClient, IPPeerServer,
System.Tether.Manager, System.Tether.AppProfile, System.Tether.TCPProtocol;
type
TForm1 = class(TForm)
TetheringManager1: TTetheringManager;
TetheringAppProfile1: TTetheringAppProfile;
Button1: TButton;
Memo1: TMemo;
procedure TetheringManager1EndManagersDiscovery(const RemoteManagers: \
TList<System.Tether.Manager.TTetheringManagerInfo>);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.fmx}
procedure TForm3.Button1Click(Sender: TObject);
begin
TetheringManager1.DiscoverManagers;
end;
procedure TForm3.TetheringManager1EndManagersDiscovery(\
const RemoteManagers: TList<System.Tether.Manager.TTetheringManagerInfo>);
var
I: Integer;
begin
for I := 0 to RemoteManagers.Count - 1 do
Memo1.Lines.Add(RemoteManagers[I].ManagerText);
end;
In this example, you fill a memo with the text of all remote managers found.
When you want to make a manager private, you have to fill the password because another manager wants to pair, it needs to know this password to be able to pair.
To pair with a remote manager, you use the method PairManager(ARemoteManager). Then if the manager is protected by password, you receive an event OnRequestManagerPassword with the remote manager identifier and a password var to fill, so you need to provide the password to be able to pair:
If the password is wrong, then you get the event OnAuthErrorFromServer.
If the pairing is fine, then you receive OnPairedToServer along with the OnEndProfilesDiscovery event with all the profiles found in that manager.
On the remote side, the manager receives:
OnAuthErrorFromClient if the password is wrong.
OnPairedFromClient if the password is correct.
Profile
To use the basic functionality, you need to add a TTetheringProfileApp, and connect that profile to the existing manager. With this you can share data and actions with other profiles.
Next you add to the profile SharedActions and/or SharedResources:
Shared Actions: A shared action is a container that stores an action link to connect with an existing TAction, and has an ItemName that is used to track that action from all clients that want to execute the action. From the remote client, the action can be executed on demand.
Shared Resources: A shared resource is a container that stores a DataValue or a Stream, and its public name that is used in order to be referenced outside.
After you configure the sharing information in the profile that you are going to share, go to the client application that is going to use the shared profile. When that application is connected to the previously shared profile, you can instruct the client application profile to execute one remote action, by providing the actual discovered remote profile and the shared name of the action:
CommandApp.RunRemoteAction(CommandManager.RemoteProfiles[LbPlayers.ItemIndex], 'acPlayPause');
Execute remote actions, exchange data and use discovery service
App Tethering
Application tethering enables your apps to interact with other apps running either on the same machine or on a remote machine.
Using tethering, your applications can:
Discover other applications that support tethering running on the same device or on other connected devices.
Share data between applications. Tethering allows sharing both strings and streams, and you can use streams to implement support for any other data structure.
Execute actions remotely. An application can publish actions using tethering; then a second application can invoke any of these actions remotely on the first application.
Tethering components: We follow the Bluetooth profile model: there is a main component, and then a profile that implements the functionality:
TTetheringManager: is the component that manages all basic operations: auto discovering and pairing with other remote managers.
TTetheringAppProfile implements the "Application Profile", a set of functionality that include executing remote actions, sharing resources and sending streams and strings between other paired profiles.
A manager needs to register a profile to start, so you need to drop a TTetheringManager component and a TTetheringAppProfile component in a form, and then link both components, filling the manager property in the profile component.
To find other tether applications in the network, your app needs to execute the method DiscoverManagers. You can set a timeout; the default timeout is 1500ms. When the timeout finishes, you receive the OnEndManagersDiscovery event, in which you receive a list of the discovered remote managers.
From this list of remote managers, you can choose the ones you want to pair with.
Example: Create a form with a button, a memo, a manager, and a profile.
uses
System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, FMX.StdCtrls,
FMX.Layouts, System.Generics.Collections, FMX.ListBox, IPPeerClient, IPPeerServer,
System.Tether.Manager, System.Tether.AppProfile, System.Tether.TCPProtocol;
type
TForm1 = class(TForm)
TetheringManager1: TTetheringManager;
TetheringAppProfile1: TTetheringAppProfile;
Button1: TButton;
Memo1: TMemo;
procedure TetheringManager1EndManagersDiscovery(const RemoteManagers: \
TList<System.Tether.Manager.TTetheringManagerInfo>);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.fmx}
procedure TForm3.Button1Click(Sender: TObject);
begin
TetheringManager1.DiscoverManagers;
end;
procedure TForm3.TetheringManager1EndManagersDiscovery(\
const RemoteManagers: TList<System.Tether.Manager.TTetheringManagerInfo>);
var
I: Integer;
begin
for I := 0 to RemoteManagers.Count - 1 do
Memo1.Lines.Add(RemoteManagers[I].ManagerText);
end;
In this example, you fill a memo with the text of all remote managers found.
When you want to make a manager private, you have to fill the password because another manager wants to pair, it needs to know this password to be able to pair.
To pair with a remote manager, you use the method PairManager(ARemoteManager). Then if the manager is protected by password, you receive an event OnRequestManagerPassword with the remote manager identifier and a password var to fill, so you need to provide the password to be able to pair:
If the password is wrong, then you get the event OnAuthErrorFromServer.
If the pairing is fine, then you receive OnPairedToServer along with the OnEndProfilesDiscovery event with all the profiles found in that manager.
On the remote side, the manager receives:
OnAuthErrorFromClient if the password is wrong.
OnPairedFromClient if the password is correct.
Profile
To use the basic functionality, you need to add a TTetheringProfileApp, and connect that profile to the existing manager. With this you can share data and actions with other profiles.
Next you add to the profile SharedActions and/or SharedResources:
Shared Actions: A shared action is a container that stores an action link to connect with an existing TAction, and has an ItemName that is used to track that action from all clients that want to execute the action. From the remote client, the action can be executed on demand.
Shared Resources: A shared resource is a container that stores a DataValue or a Stream, and its public name that is used in order to be referenced outside.
After you configure the sharing information in the profile that you are going to share, go to the client application that is going to use the shared profile. When that application is connected to the previously shared profile, you can instruct the client application profile to execute one remote action, by providing the actual discovered remote profile and the shared name of the action:
CommandApp.RunRemoteAction(CommandManager.RemoteProfiles[LbPlayers.ItemIndex], 'acPlayPause');