Using the Programming API¶
This chapter introduces the basic usage of the API, allowing you to understand another way to use FIRERPA. FIRERPA provides as many as 160 programming API interfaces, enabling you to manage and operate Android devices with meticulous control. It offers interfaces in over a dozen major categories, including command execution, system settings, system status, application-related, automation-related, proxy, and files. It also provides a fully encapsulated Python library to help you get started quickly. Before proceeding, please ensure that the FIRERPA server is running correctly on your phone and that the FIRERPA client library has been installed as required. Now, let's begin the tutorial.
A quick note: Many of the API interfaces provided by FIRERPA return native proto classes. You can directly access these values through the attributes of the output, or by viewing the proto definition. For example, if an interface returns the following value, you can access a specific field as shown in the example.
>>> result = status.get_battery_info()
>>> print (result)
batt_charging: true
batt_percent: 100
batt_temperature: 26.899999618530273
>>> print (result.batt_temperature)
26.899999618530273
Connecting to a Device¶
Before connecting to a device, you need to have some necessary information ready, such as the IP address that can connect to your phone and whether you used a service certificate when starting FIRERPA. Once you have this information, you can proceed with the following steps.
Instantiate the device. By default, you only need to provide an accessible IP address.
from lamda.client import *
d = Device("192.168.0.2")
If you enabled a service certificate when starting the FIRERPA server, connect like this.
from lamda.client import *
d = Device("192.168.0.2", certificate="/path/to/lamda.pem")
From now on, the d variable in the following text will always refer to this Device instance.
Simple Warm-up¶
Now, execute the following code. This line of code will display a message Hello from Lamda! on your screen.
d.show_toast("Hello from Lamda!")
You can also use the following interface, which makes the device emit a beep. This is useful for locating a specific device when you have many of them (the phone must not be in silent mode).
d.beep()
Alright, now that you understand how to use it, you can continue reading to learn about other available interfaces and how to use them.