You not specified react native version number.
I used same 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.
- in android/app/build.gradle:
dependencies {
...
compile "com.facebook.react:react-native:+" // From node_modules
+ compile project(':react-native-device-info')
}
- 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')
- 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.