react-native-telephony-manager

1.6.1 • Public • Published

React Native Telephony Manager

Installation

Add the package to your react-native project in the following way

npm install react-native-telephony-manager

OR

yarn add react-native-telephony-manager

Link the current package to your react native project

react-native link react-native-telephony-manager

Usage

import Telephony from 'react-native-telephony-manager'

componentWillMount() {
  Telephony.addEventListener(Telephony.LISTEN_CALL_STATE | Telephony.LISTEN_DATA_ACTIVITY,
  (event) => {
    if (event.type === 'LISTEN_CALL_STATE') {
      console.log(event.data)
    } else {
      console.log(event.data)
    }
  })

  Telephony.isNetworkRoaming((roaming) => {
    if (roaming) {
      // ...
    }
  })

  Telephony.getNetworkClass((network) => {
    switch(network) {
      case "2G":
        // ...
      break;
      case "3G":
        // ...
      break;
      case "4G":
        // ...
      break;
      default:
        // ...
      break;
    }
  })

  Telephony.getCellInfo((cellInfos) => {
    celInfos.map((info) => {
      switch(info.connectionType) {
        case "CDMA":
          console.log(info.cellIdentity)
          console.log(info.cellSignalStrength)
        break;
        case "WCDMA":
          console.log(info.cellIdentity)
          console.log(info.cellSignalStrength)
        break;
        case "GSM":
          console.log(info.cellIdentity)
          console.log(info.cellSignalStrength)
        break;
        case "LTE":
          console.log(info.cellIdentity)
          console.log(info.cellSignalStrength)
        break;
        default:
          // ...
        break;
      }
    })
  })
}

componentWillUnmount() {
  Telephony.removeEventListener()
}

Events

Telephony.LISTEN_CALL_FORWARDING_INDICATOR
Telephony.LISTEN_CALL_STATE
Telephony.LISTEN_CELL_INFO
Telephony.LISTEN_CELL_LOCATION
Telephony.LISTEN_DATA_ACTIVITY
Telephony.LISTEN_DATA_CONNECTION_STATE
Telephony.LISTEN_MESSAGE_WAITING_INDICATOR
Telephony.LISTEN_SERVICE_STATE
Telephony.LISTEN_SIGNAL_STRENGTHS

LISTEN_CALL_STATE states

Telephony.CALL_STATE_IDLE
Telephony.CALL_STATE_RINGING
Telephony.CALL_STATE_OFFHOOK

LISTEN_DATA_ACTIVITY states

Telephony.DATA_ACTIVITY_NONE
Telephony.DATA_ACTIVITY_IN
Telephony.DATA_ACTIVITY_OUT
Telephony.DATA_ACTIVITY_INOUT
Telephony.DATA_ACTIVITY_DORMANT

LISTEN_DATA_CONNECTION_STATE states

Telephony.DATA_DISCONNECTED
Telephony.DATA_CONNECTING
Telephony.DATA_CONNECTED
Telephony.DATA_SUSPENDED

For any problems and doubt raise an issue.

Package Sidebar

Install

npm i react-native-telephony-manager

Weekly Downloads

4

Version

1.6.1

License

MIT

Unpacked Size

195 kB

Total Files

45

Last publish

Collaborators

  • bozhidar.bozhanov