I am trying to get device id from android device. There are several links and packages available to get device id but very few are usable in case of Android. Below are links i had tried already with no results:
Link1: https://github.com/rebeccahughes/react-native-device-info I had tried this link with no success it may run fine on ios but on Android it is showing me error while running mentioned command on github link "react-native link react-native-device-info" Error: Link unrecognised
Link2: https://github.com/lazywei/react-native-device-uuid It has solution only for IOS
I am stuck here. I am getting no idea how i will resolve this issue? Please help?
Thanks in advance
React Native Device ID The device ID uniquely identifies the devices and is determined automatically by the SDK. In the React Native SDK, we use the platform-specific logic for iOS or Android as covered in detail above.
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.
dependencies { ... compile "com.facebook.react:react-native:+" // From node_modules + compile project(':react-native-device-info') }
...
include ':app'
include ':react-native-device-info'
project(':react-native-device-info').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-device-info/android')
+ 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.
You can install this package : https://github.com/rebeccahughes/react-native-device-info
And then use it
import DeviceInfo from 'react-native-device-info';
const uniqueId = DeviceInfo.getUniqueID();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With