目录

Communication

API Declaration

Add the following configuration to the features attribute in the manifest.json file:

{"name": "system.telecom"}

Modules Import

Add the following configuration to the script element on the page where the API will be called:

import telecom from '@system.telecom'

Or

var telecom = require("@system.telecom")

Application Scope

Item

Description

Applicable devices

Mobile phones and tablets

Applicable regions

Global

Definition

API

Description

telecom.getTelecomInfo(OBJECT)

Obtains the device communication information, checks whether the device supports 5G, and checks whether 5G is enabled.

[h2]telecom.getTelecomInfo(OBJECT)

Description

Obtains the device communication information, checks whether the device supports 5G, and checks whether 5G is enabled.

OBJECT

Parameter

Type

Mandatory

Description

success

function

No

Callback upon success.

fail

function

No

Callback upon failure.

complete

function

No

Callback upon completion.

Parameters returned by success

Parameter

Type

Description

is5GDevice

boolean

The value is true for 5G devices.

NOTE:

A device is considered as a 5G device only when it supports 5G and is connected to the 5G network.

is5GSwitchOpened

boolean

Indicates whether 5G is enabled. true indicates yes.

Result codes returned by fail

Result Code

Description

200

Common error.

202

A user refuses your app to read the device status.

Sample code

telecom.getTelecomInfo({
  success:function(data) {
    console.log('success --> is5GDevice: ' + data.is5GDevice + ', is5GSwitchOpened: ' + data.is5GSwitchOpened);
  },
  fail:function(errorMessage, errorCode) {
    console.log('fail --> errorMessage: ' + errorMessage + ', errorCode: ' + errorCode);
  },
  complete:function() {
    console.log('getTelecomInfo.complete');
  }});

Demo

<template> 
<div class="container">
  <div  class="item-container">
    <text>is5GDevice:</text>
    <text>{{telecomInfo.is5GDevice}}</text>
    <text>is5GSwitchOpened:</text>
    <text>{{telecomInfo.is5GSwitchOpened}}</text>
    <input class="btn" type="button" value="getTelecomInfo" onclick="gettelecominfo" /> 
  </div>
</div> 
</template> 
<style lang="sass"> 
 .container{
  flex: 1;
  flex-direction: column;
} 

  .item-container {
    margin-bottom: 50px;
    margin-right: 60px;
    margin-left: 60px;
    flex-direction: column;
  }

  .btn {
      background-color: #00bfff; 
      color: #ffffff; 
  }

</style> 
<script> 
import router from '@system.router';
import telecom from '@system.telecom';
  module.exports = { 
    data: { 
      enableSwipe: true,
      telecomInfo:{ } 
    }, 
    onInit () {
      this.$page.setTitleBar({ text: 'telecom' })
    },
    gettelecominfo() {
        var that = this
          telecom.getTelecomInfo({
              success: function (data) {
                  console.log('success --> is5GDevice: ' + data.is5GDevice + ', is5GSwitchOpened: ' + data.is5GSwitchOpened);
                  that.telecomInfo = data
              },
              fail: function (errorMessage, errorCode) {
                  console.log('fail --> errorMessage: ' + errorMessage + ', errorCode: ' + errorCode);
              },
              complete: function () {
                  console.log('getTelecomInfo.complete');
              }
          });
      }
  } 
</script>

The following figure shows the final effect.

Version Change History

Version

Date

Description

1080

2021-12-28

First official release.