Get device id in react native?

expo get device id
react-native-device-info timezone
react-native get country code
get device type react-native
how to get uuid in react-native
react-native get user id
react-native get timezone
react-native get user agent

how to get device id in react native. I am using create react native not android studio. I am new to this.

import DeviceInfo from 'react-native-device-info';

constructor(props) {
 super(props);
   this.state = { id: '' }
   this.onNavigateTo = this.onNavigateTo.bind(this);   
}
componentDidMount() {
   this.setState({id: DeviceInfo.getUniqueID()}, () =>      
   alert(this.state.id));
}
render() {
  return (
       <Text>{this.state.id}</Text>
  );
}

Error: undefined is not an object (evaluating 'RNDevice.uniqueId')

Note:- I am not using run-android or run-ios

I am using Create-react-native app and yarn start. The output will be on device through Expo app

you cannot use library that use native code with expo see caveats if you want to use native code you need to create your project with native code at getting started doc basically

  1. install pre request apps (node - Java Development Kit - android studio - xcode - react native cli )
  2. run command react-native init MyProjectName
  3. cd your project folder cd MyProjectName
  4. run react-native run-android or react-native run-ios

if you want to convert expo project to native code project you can do ejecting-from-create-react-native-app

  1. install native code requirement as above
  2. run npm run eject

after that you can use third party libraries that use native code and run react-native link

react-native-device-info, Unique Id of Device. Every mobile device in the world has its unique ID which is a combination of Alphabetic and Numeric characters. To get the device's Unique  import DeviceInfo from 'react-native-device-info'; constructor(props) { super(props); this.state = { id: '' } this.onNavigateTo = this.onNavigateTo.bind(this); } componentDidMount() { this.setState( {id: DeviceInfo.getUniqueID()}, () => alert(this.state.id)); } render() { return ( <Text> {this.state.id}</Text> ); }

Instead of expo you can create a project using react-native CLI.

Create a new project using command :

react-native init Myproject

cd Myproject

Run the project using the following command :

react-native run-android

Then you can use react-native-device-info package.

I tried with following versions and it worked for me.

  "react": "16.0.0",
  "react-native": "0.50.4",
  "react-native-device-info": "^0.12.1",

I installed it with command :

npm install --save react-native-device-info

Then I link it with command :

react-native link react-native-device-info

If you are facing any issue while linking the package then you can do the manual link or you can cross check the packages is successfully link or not.

  1. in android/app/build.gradle:
 dependencies {
        ...
        compile "com.facebook.react:react-native:+"  // From node_modules
    +   compile project(':react-native-device-info')
    }
  1. in android/settings.gradle:

...

include ':app'

include ':react-native-device-info'

project(':react-native-device-info').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-device-info/android')

  1. in MainApplication.java:
+ import com.learnium.RNDeviceInfo.RNDeviceInfo;

  public class MainApplication extends Application implements ReactApplication {
    //......

    @Override
    protected List<ReactPackage> getPackages() {
      return Arrays.<ReactPackage>asList(
+         new RNDeviceInfo(),
          new MainReactPackage()
      );
    }

    ......
  }

Permissions

Add the appropriate, optional permissions to your AndroidManifest.xml:

...
<uses-permission android:name="android.permission.BLUETOOTH"/>         <!-- for Device Name -->
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>  <!-- for Phone Number -->

Example

var DeviceInfo = require('react-native-device-info');
// or import DeviceInfo from 'react-native-device-info';

var deviceId = DeviceInfo.getUniqueID();

you can use above deviceId.

React Native Get Unique ID of Device, you cannot use library that use native code with expo see caveats if you want to use native code you need to create your project with native  Lets see the complete source code that helps to get android or ios device unique ID in react native application with simple example. Step 1: Create a new react native project, if you don’t know how to create a new project in react native just follow this tutorial. Step 2: Open your react native project folder in CMD or Terminal and execute the below command to install the react-native-device-info library.

If you are using Expo try this.

import Constants from 'expo-constants';
this.clientId = Constants.deviceId;

Get device id in react native?, Building a great React Native app more likely requires retrieving the mobile device details like the operating system, version, bundle ID and much more. React Native - Get Device Unique ID Using react-native-device-info. Sometimes it is necessary to find out device’s unique identifier. There’s a handy library that helps you to do that. react-native-device-info will do that for you.

If your goal is to get a client unique ID, then you might want to use NativeModules.

Import { NativeModules } from 'react-native'

on your component...

for iOS: console.log(NativeModules.SettingsManager.clientUniqueId) for Android: console.log(NativeModules.PlatformConstants.fingerprint); (or NativeModules.PlatformConstants.serial)

The Easiest Way to Get React Native Device Information, To get unique device ID android or ios we have to install act-native-device-info package, in our project directory first. NPM command : npm install  To get the device information in React Native will use the react-native-device- info library. In this example, we will show you how to get all the information about the device using a single library. We will get the following details in this example. So let’s get started with the example to Get Device Info.

getUniqueId is not reliable on Android using react-native-device-info, see the issue below: - https://github.com/rebeccahughes/react-native-device-info/issues/355

There is a PR waiting to be released: - https://github.com/rebeccahughes/react-native-device-info/pull/358

After releasing this change, you can get the unique id using getUUID

React Native Get Android or iOS Device Unique ID Dynamically , Both android and iOS devices supports Unique ID and using the react-native-​device-info NPM library we can easily retrieve Get Android iOS  Calling the React Native Device Info Plugin To start reading the device info, you can call any of the following plugin APIs based on what you need to do in your app. DeviceInfo.getUniqueID() - to get the device unique ID. This ID will change if the app is uninstalled.

React Native Get Android iOS Device Unique ID Dynamically Example, The new best way to get started is by running create-react-app my-presentation --​scripts-version spectacle-scripts. I used same react-native-device- info package  I have been using the unique device id from react-native-device-info on Android for several months without any issues. Why not just add the feature, and just deprecate it if Google ever rejects the Expo app because of that? Better to have extra features than avoiding it completely because there's a risk that it might be rejected

Reactjs get device id, Has anyone gotten this full thing set up and working? Basically what I'm looking for is how to get the device ID after assigning a device to a user  import DeviceInfo from 'react-native-device-info'; // or ES6+ destructured imports import {getUniqueId, getManufacturer} from 'react-native-device-info'; API Note that many APIs are platform-specific.

Get Device ID & Name after Setup (iOS & React Native), If you're installing this in a bare React Native app, you should also follow these ID . On iOS, this is the same value as Device.osBuildId . On web, this value is null . Gets the uptime since the last reboot of the device, in milliseconds. React Native. With React Native you can develop native mobile applications for iOS and Android using JavaScript and React. It is created by Facebook and used for such well-known apps as Instagram, Airbnb, and now JetBrains’ own YouTrack mobile application.

Comments
  • Did you run the link command?
  • yes step : 1 npm install --save react-native-device-info step : 2 react-native link react-native-device-info
  • Have you tried to clean the yarn cache? Not sure if it would help, but people are saying if they run react-native run-ios again, it would fix the issue, since you are doing yarn, maybe try that as well..
  • yeah lemme try !!!!!!!!!!!
  • nope not working ??
  • for me its building successfully but in device telling me the same problem
  • i am getting but i can get the ID only after build
  • Not working!!!!