The International Mobile equipment Identity (better known by the acronym IMEI) is a number, typically unique, which identifies mobile phones. It is usually printed inside the battery slot, however you can also print it on the screen by typing*#06#.

Você está assistindo: Como obter o imei do celular

This number likewise can it is in obtained, having ns respective permissions of the Android OS, são de an application. This time we’ll a partir de it from an React native application.

Prior to a process, you have to ensure the you have actually an updated version of npm:

npm i -g npmLater, if friend still do not have a create-react-native-app parcel installed, install it as follows:

npm download -g create-react-native-appStart through creating ns react native projeto with ns following statement:

create-react-native-app ReactIMEINext, walk to the projeto directory the you simply created:

cd ReactIMEIAnd prove that ns application runs successfully:

yarn startDepending on where you estão going to check our application, select ns interactive CLI option that is presented after executing yarn start.

For this example we will usar an Android emulator (Option a).


The maker screen will existing something like a following:



It is a React Native library that enables us to conveniently obtain ns IMEI, as long as ns application is running on an Android device e has ns READ_PHONE_STATE permission. This is the library that we’re going come use ao our example.

Integrating react-native-imei to our project

To add the library ao our example project, run the following command:

yarn include react-native-imeiSince react-native-device-imei is naquela library that contains native code, you must attach it come our application.

Prior to the link to ns native library, you should eject a partir de the CRNA application (Create React aboriginal App) to transform it into der React aboriginal Regular application. The steps come follow are described in ns CRNA main documentation. Ns output of a process will certainly look similar to the following:


After performing the eject process, you can link the library:

react-native connect react-native-imeiThe output will certainly be o mesmo, semelhante to ns following:


Once the biblioteca is linked, friend can use it; porque o this, modify the App.js file that is in the project’s source directory.

First, modify a render duty so that it shows naquela button (TouchableOpacity) which, after clicking on it, will show the an equipment IMEI in der text field.

render () return ( this.state.DeviceIMEI CLICK aqui TO importar DEVICE IMEI )In addition to this, initialize DeviceIMEI as part of ns state in ns App component’s constructor:

constructor () super() this.state = DeviceIMEI: '', Finally, implement the function getDeviceIMEI i m sorry contains the logic to compreendo the device IMEI:

getDeviceIMEI = () => const IMEI = require('react-native-imei') this.setState( DeviceIMEI: IMEI.getImei(), )After performing todos the actions above, the complete file will look favor this:

import React from 'react'import StyleSheet, Text, View, TouchableOpacity from 'react-native'export default class App extends React.Component constructor () super() this.state = DeviceIMEI: '', getDeviceIMEI = () => const IMEI = require('react-native-imei') this.setState( DeviceIMEI: IMEI.getImei(), ) wailer () return ( this.state.DeviceIMEI CLICK here TO vai DEVICE IMEI ) const styles = StyleSheet.create( container: flex: 1, backgroundColor: '#fff', alignItems: 'center', justifyContent: 'center', ,)Testing a operation in an emulatorTo test a operation of a app, open ns android/ brochure in Android Studio.

The following step is to começar Metro Bundler by yarn start:


As naquela final step, run ns app in one emulator from Android Studio, a directory will be well-known as an Android project:

If you chosen this article, please applaud as many times as girlfriend wish. You can also read this short article in Spanish. To see semelhante stories about technology, look at our publications. Dá not hesitate to leave united state in ns comments box any concerns or proposal you may have.

If girlfriend need der great team that will certainly advise friend in expressing your ideia in React JS or React Native, dá not hesitate to contact us. You can go come our website e fill o fim the form e we will contact you as quickly as possible.

Miguel torres VivancoMail: miguel


Problem: when creating ns application using create-react-native-app, the following message shows up at ns end:

error An unforeseen error occurred: " Invalid tar header. Maybe a tar is corrupted or it needs to be gunzipped?".Cause: typically it is because the create-react-app package offers (updated at the time of writing this publication) naquela discontinued variation of Yarn. This blog post is found in the initial lines after executing ns create-react-app command:

warning Your existing version that Yarn is lado de fora of date. A latest variation is "1.7.0" while you're ~ above "0.23.3".Solution: Update ns Yarn variation as said in ns following lines:

info come upgrade, run ns following command:$ npm update --global yarnAnd verify that a version that Yarn is updated:

yarn --versionIf ns Yarn version has not changed, you have the right to force a update to der specific version, a most current stable version (1.7.0 at ns time of writing this article)

npm install -g yarn
1.7.0And verify a version again.

Ver mais: Como Transferir Livros Para O Kindle Para Outro, Como Transferir Arquivos (Pdf, Word, Etc

Next, delete the directory created that gave ns error:

rm -rf ReactIMEIFinally, create a application again:

create-react-native-app ReactIMEIProblem:

react-native: command no foundCause: The react-native-cli module is not set up in your system.