• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Obtaining Current Cellular Network Signal Information
2
3
4## Use Cases
5
6Applications always need to obtain signal information of the registered cellular network to obtain the network quality. You can use this service to obtain the network signal information for the specified SIM card.
7
8
9## Available APIs
10
11The radio module provides you with APIs to obtain network signal information. The observer module provides APIs to register or unregister the observer for cellular network status changes. The following table describes the related APIs.
12
13| Category| API| Description| Required Permission|
14| -------- | -------- | -------- | -------- |
15| Obtaining a **SignalInformation** object| radio.getSignalInformation​​() | Obtains the signal strength of the currently registered cellular network.| N/A|
16| Registering the observer for signal information changes| observer.on('signalInfoChange') | Registers the observer for signal information changes.| N/A|
17| Unregistering the observer for signal information changes| observer.off('signalInfoChange') | Unregisters the observer for signal information changes.| N/A|
18
19
20## How to Develop
21
221. Import required modules.
23
242. Call the **getSignalInformation()** API to obtain the **SignalInformation** list.
25
263. Traverse the **SignalInformation** list to obtain the signal strength for each radio access technology (RAT) indicated by **signalType**.
27
284. (Optional) Register the observer for signal information changes.
29
30   ```js
31   import radio from '@ohos.telephony.radio'
32   import observer from '@ohos.telephony.observer';
33
34   // Obtain the signal strength of the specified SIM card, for example, card 1.
35   let slotId = 0;
36   radio.getSignalInformation(slotId, (err, data) => {
37       if (!err) {
38           console.log("get signal information success.");
39           // Traverse the signal information list to obtain the signal strength for each RAT.
40           for (let j = 0; j < data.length; j++) {
41               console.log("type:" + data[j].signalType + ", level:" + data[j].signalLevel);
42           }
43       } else {
44           console.log("get signal information fail, err is:" + JSON.stringify(err));
45       }
46   });
47   // (Optional) Register the observer for signal information changes.
48   observer.on("signalInfoChange", (data) => {
49       console.log("signal info change, data is:" + JSON.stringify(data));
50   });
51   ```
52