(react-native study of Nine) Use of React-native-device-info:

Source: Internet
Author: User
Tags arrays unique id

Preface: As the name implies React-native-device-info this third party is to obtain equipment information.

In fact, React-native have many similar third parties and are used in much the same way as in this case. As an example record, for students who need to learn: 1, initialize the project:

Initialize a react-native project: command:

Win+r//Enter command line

CD desktop//Enter desktop

react-native  init deviceinfodemo//Initialize  react-native project:

CD Deviceinfodemo//Enter the project root

yarn Install//or NPM Install 

Project initialization is complete. 2. Open the emulator.

Use the following emulator command (if the environment variable is already configured):

EMULATOR-LIST-AVDS//This command is used to view the Android  emulator that exists under the current computer 

EMULATOR-AVD vm_name//Modify Vm_name to open the emulator for the emulator name in your current computer  .

or open the Androidstudio tool and open SDK Manager to open the emulator.

After you start the emulator you can run the react-native run-android command. The emulator will appear with our initialized Project interface:

3, installation and linking Device-info:

Go to the project root to execute the command installation React-native-device-info

Using NPM:
npm install--save react-native-device-info

//or using yarn:
yarn Add React-native-device-info

Don't forget to check if the installation was successful. Auto Link:

Execute command:

Shell
react-native link React-native-device-info


//(or using [' RNPM '] (HTTPS://GITHUB.COM/RNPM/RNPM) for Versions of React Native < 0.27) 
RNPM link React-native-device-info
Manual Link:


Android Manual link Open android/build.gradle:

...
  ext {
    //dependency versions
    Googleplayservicesversion = "<your Services version>"
  }
...
Enter Android/app/build.gradle: Add Device-info Dependency
dependencies {
    ...
    Compile "com.facebook.react:react-native:+"  //from Node_modules
+   Compile project (': React-native-device-info ')
}
Enter Android/settings.gradle: Specify Device-info Directory
...
Include ': App '
+ include ': React-native-device-info '
+ Project (': React-native-device-info '). ProjectDir = new File (Rootproject.projectdir, '. /node_modules/react-native-device-info/android ')
for React Native 0.29+ It is also necessary to:Enter 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 (),  //Add this line
          new Mainreactpackage ()
      );
    }

    ......
  }
for low version React Native:Enter Mainactivity.java: Main interface
+ Import Com.learnium.RNDeviceInfo.RNDeviceInfo;

  public class Mainactivity extends Reactactivity {
    ...

    @Override
    protected list<reactpackage> getpackages () {
      return arrays.<reactpackage>aslist (
+       New Rndeviceinfo (),  //Add  moudle
        new Mainreactpackage ()
      );
    }
  }

Other platforms are not repeating. Readers can refer to the official address link at the end of the article.

paste the Device-info part of the API method: API

Method return value type IOS Android Windows Since
Getapilevel ()//Get Application API version Number 0.12.0
Getapplicationname ()//Get app Name String 0.14.0
Getbrand ()//Get Factory String 0.9.3
Getbuildnumber ()//Get application compilation version number String ?
Getbundleid ()//Get the application package identifier String ?
Getcarrier ()//Get the name of the operator String 0.13.0
Getdevicecountry ()//Get device country based on locale information. String 0.9.0
Getdeviceid ()//Get Device ID String 0.5.0
Getdevicelocale ()//access to the area of the device String 0.7.0
Getdevicename ()//Get device Name String ?
Getfirstinstalltime ()//Gets the time, in milliseconds, for the application to install for the first time. Number 0.12.0
Getfontscale ()//Gets the device font size. Number 0.15.0
Getfreediskstorage ()//Gets the available storage size, in bytes. Number 0.15.0
Getipaddress ()//Get the current network address of the device Promise<string> 0.12.0
Getinstanceid ()//Gets the application instance ID. String ?
Getlastupdatetime ()//Gets the time, in milliseconds, when the application was last updated. Number 0.12.0
Getmacaddress ()//Get the network adapter MAC address. Promise<string> 0.12.0
Getmanufacturer ()//Get the device manufacturer. String ?
Getmaxmemory ()//returns the maximum amount of memory, in bytes, that the JVM is trying to use. Number 0.14.0
Getmodel ()//Get device mode String ?
Getphonenumber ()//Get phone number String 0.12.0
Getreadableversion ()//Take the application-readable version. String ?
Getserialnumber ()//Get serial number String 0.12.0
Getsystemname ()//Get system name String ?
Getsystemversion ()//Get System version String ?
getTimeZone ()//Get time zone String ?
Gettotaldiskcapacity ()//Gets the full disk storage size, in bytes. Number 0.15.0
Gettotalmemory ()//Gets the total memory of the device, in bytes. Number 0.14.0
Getuniqueid ()//Get the device unique ID String ?
Getuseragent ()//Get device User Agent String 0.7.0
GetVersion ()//Get version String ?
Is24hour ()//Tell users if preference is set to 24-hour format Boolean 0.13.0
Isemulator ()//Tell the application to run in the emulator Boolean ?
Ispinorfingerprintset ()//tells the device whether a PIN number or fingerprint is set (callback) Boolean 0.10.1
Istablet ()//Tell the device whether it is a Tablet PC Boolean ?
The following is the information hardware information obtained by the blogger virtual machine:

Code Address: Github:https://github.com/zqhero/deviceinfodemo

Official address See:
Https://www.npmjs.com/package/react-native-device-info

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.