0

I need IMEI for validation in a React Native app. Using reactive-native-imei package, here is the link to that package: (https://github.com/SimenCodes/react-native-imei).

during my code I am getting the following errors:-

  1. In my Code here;
const GetImei = () => {
    const IMEI = require('react-native-imei');
    IMEI.getImei().then(imeiList => {
        console.log(imeiList); // prints ["AABBBBBBCCCCCCD"]
    });

In the second line of my code const IMEI = require('...react-native-imei'); It is giving me that 3 dots below 'r' of react-native-imei and when I hover over it, it's saying "could not find declaration file for module- 'react-native-imei' ", though I have installed the package and also linked it, I also checked In the node-module the package is still there also I have checked settings.gradle file the package is included there so what could be the reason of this error? please help me.

  1. some other errors I am getting are given in the below images: enter image description here enter image description here enter image description here

2 Answers 2

1

check this issue. It is raised in library.

https://github.com/SimenCodes/react-native-imei/issues/22

If you are in a very particular situation, you can use this library in recent Android versions as well. "Just" follow Android's rules for obtaining the extra permission. There's some hints in the discussion from 2019, but you should know that the permission has been renamed to READ_PRECISE_PHONE_STATE since then.

check in android documentation also.

https://developer.android.com/about/versions/10/privacy/changes?authuser=1#non-resettable-device-ids

4
  • So it means we cant access the IMEI number now in react-native? Is this what it says? Commented Dec 17, 2021 at 6:10
  • No. we will get IMEI number once we have READ_PRIVILEGED_PHONE_STATE permission. Which is already explained in Doc above.
    – Balu
    Commented Dec 17, 2021 at 12:46
  • So if I change <uses-permission android:name="android.permission.READ_PHONE_STATE"/> to <uses-permission android:name="android.permission.READ_PRIVILEGED_PHONE_STATE" /> will it be OKAY? Commented Dec 17, 2021 at 14:12
  • Just give it a try. Place permission in androidmanifest.xml file and request runtime permission through PermissionsAndroid.
    – Balu
    Commented Dec 18, 2021 at 5:16
-1

I dont actually know what exactly caused the error in your application but I have build a demo base on your given library and it works fine. Here is my code :

import React from 'react'
import { StyleSheet,TouchableOpacity ,Text,View} from 'react-native'

export default class Demo extends React.Component {

  constructor () {
    super()
    this.state = {
      deviceIMEI: '',
    }
  }

  getIMEI = () => {
    const IMEI = require('react-native-imei')
    this.setState({
      deviceIMEI: IMEI.getImei(),
    })
  }

  render () {
    return (
      <View style={styles.container}>
        <Text>{this.state.deviceIMEI}</Text>
        <TouchableOpacity onPress={this.getIMEI}>
          <Text>Get Current Device IMEI</Text>
        </TouchableOpacity>
      </View>
    )
  }
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: 'flex-start',
  },
})
2
  • What about "In the second line of that code "const IMEI = require('...react-native-imei');" It is giving me that 3 dots below 'r' of react-native-imei and when I hover over it, it's saying "could not find a declaration file for module- 'react-native-imei' ", though I have installed the package and also linked it, I also checked In the node-module the package is still there also I have checked settings.gradle file the package is included there so what could be the reason of this error?" Commented Dec 17, 2021 at 5:11
  • I am running your code now it is giving me an error : Objects are not valid as a React child (found: object with keys {_U, _V,_W,_X}). Commented Dec 18, 2021 at 13:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.