React Native Get Android Device IMEI Number on Button Click Example Tutorial

IMEI number also known as International Mobile Equipment Identity Number is a unique number given to every mobile phone in the world. IMEI number helps the mobile department to identify each and every mobile present on the globe. IMEI number is most probably used to stop a stolen mobile phone to used again by some other person and helps the police and telecom department track the stolen mobile phone. But in many cases like identifying every device uniquely from the application server its very helpful to because with them the application developer can easily take record of its user individually. So in this tutorial we would going to make a tutorial to Get Android Device IMEI Number on Button Click in React Native Example Tutorial.

Note: Apple dose not allow us to access device personal information like IMEI number so you cannot get the IMEI number in IOS devices. Read this post for further information.

Contents in this project Get Android Device IMEI Number on Button Click in React Native Example Tutorial:

1. Before getting started we need to install the react-native-imei npm library in our current react native project. So open your project folder in CMD or terminal and execute below command.

Screenshot of CMD :s

Screenshot of CMD after successfully executing above command:

2. Now we need to execute the  react-native link react-native-imei command into our project folder, This command would refresh the complete react native project folder and index the newly installed IMEI library.

3. We need to put the android’s READ_PHONE_STATE permission in the AndroidManifest.xml file. Because this type of personal information can be only be accessible after asking for this permission. So goto YourReactNativeProject-> android -> app -> src -> main -> AndroidManifest.xml file and put the below permission inside it.

4. Now we need to specify android:minSdkVersion and android:targetSdkVersion in our AndroidManifest.xml . This step is very important.

Source code of AndroidManifest.xml file after adding above code:

5. Open YourReactNativeProject -> android -> app -> build.gradle file and find targetSdkVersion and set its to 23 like targetSdkVersion 23 in default Config block.

6. Import Platform, StyleSheet, View, PermissionsAndroid, Text, Alert and Button component in your project.

7. Create a ASYNC function named as request_READ_PHONE_STATE() in your App.js class. Using this function we will ask for READ_PHONE_STATE permission from application user.  If you want to learn more about Requesting runtime permissions then read our this explained tutorial.

8. Create a class named as App, This would be our main export default class.

9. Creating constructor() method in your App class and inside the constructor we would make a State named as device_IMEI . This state is used to shoe the IMEI number inside text component.

10. Creating a async componentDidMount() function and call the request_READ_PHONE_STATE() function using await method. So when the app starts for the first time then it will ask for runtime permission.

11. Creating a function named as get_IMEI_Number() in your class, We would call this function on button onPress event . Inside this function we would first import the require(‘react-native-imei’) library object into IMEI constant, Now using the IMEI.getImei() inbuilt function of library we would get the IMEI number of device and set into STATE.

12. Creating a Button and Text component inside the render’s return block.

13. Creating Style.

14. Complete source code for App.js File :


Get Android Device IMEI Number


  1. Hi admin , can yo make a tutorial on Image Detection using Google Vision

  2. i got this error bro, when clicking button.
    undefined is not an object (evaluating ‘n.NativeModules.IMEI.imei’)

  3. Execution failed for task ‘:react-native-imei:verifyReleaseResources’

  4. Task :react-native-imei:compileDebugJavaWithJavac
    Note: C:\Users\Srikanth Vennu\Desktop\check\ddexcg\reimei\imei\node_modules\react-native-imei\android\src\main\java\codes\simen\IMEI\ uses or overrides a deprecated API.
    Note: Recompile with -Xlint:deprecation for details.

    > Task :app:processDebugResources FAILED

    FAILURE: Build failed with an exception.

    * What went wrong:
    Execution failed for task ‘:app:processDebugResources’.
    > Unable to delete directory ‘C:\Users\Srikanth Vennu\Desktop\check\ddexcg\reimei\imei\android\app\build\generated\not_namespaced_r_class_sources\debug\processDebugResources\r\android\arch\lifecycle’ after 10 attempts

  5. Bhai I’m getting this type of error

  6. Bhai I’m integrating firebase push notifications into IMEI and device information in android.
    Do we have any source code for these integration codes?
    I tried but I didn’t get the output every time it shows an error.

    • Sorry Bhai, I have no source code for firebase push notifications did you integrate Google login using firebase in react native ?

  7. No Bhai.

  8. Sorry Bhai, I didn’t work on that.

  9. Admin,
    Thanks for your excellent working example. Can you provide any
    sample code for saving the IMEI to a text file on the local hard drive ?

  10. Admin,
    Thanks for your prompt reply. My requirement is to save the
    IMEI to an apache/MYSQL database or a imei.txt file on C:\IMEIS on my laptop. Is there a way to echo/verify the IMEI received on the php side ? If the value is not coming then it’s another issue.

  11. I built and deployed your sample to a real Android device. I get the alerts but when I click to display the IMEI the app crashes. Any ideas ? Thanks

    • DannyC did you add the permission ?

      • Admin,
        Android permissions were added from the command line and in the AndroidManifest.xml file as READ_PHONE_STATE. I ran your app in 2018 on a S8/S9 phones and it worked. I rebuilt your app last week and now when I click to get IMEI it returns [object Object ] on my S8. I’ve tried to use JSON.stringify() for the IMEI as well and it also fails. Does the react-native-imei library still work ?
        Do you know of any devs who have succeeded getting the IMEI
        recently ? Thanks

  12. i am getting this error:-
    getImeiForSlot: the user 10503 does not meet the requirements to access device identifiers.

Leave a Reply

Your email address will not be published. Required fields are marked *