Commit eaca0b12 authored by Viktor Dlouhy's avatar Viktor Dlouhy Committed by GitHub

Merge branch 'master' into master

parents 290c3bff c362de2b
...@@ -143,13 +143,14 @@ include ':app' ...@@ -143,13 +143,14 @@ include ':app'
(Thanks to @josephan for writing the instructions) (Thanks to @josephan for writing the instructions)
## Device Name ## Permissions
If you want to get the device name in Android add this to your `AndroidManifest.xml` (optional): Add the appropriate, optional permissions to your `AndroidManifest.xml`:
```xml ```xml
... ...
<uses-permission android:name="android.permission.BLUETOOTH"/> <uses-permission android:name="android.permission.BLUETOOTH"/> <!-- for Device Name -->
<uses-permission android:name="android.permission.READ_PHONE_STATE"/> <!-- for Phone Number -->
``` ```
## Release Notes ## Release Notes
...@@ -184,9 +185,13 @@ var DeviceInfo = require('react-native-device-info'); ...@@ -184,9 +185,13 @@ var DeviceInfo = require('react-native-device-info');
| App Instance ID | `getInstanceID()` | | ANDROID ONLY - see https://developers.google.com/instance-id/ | | App Instance ID | `getInstanceID()` | | ANDROID ONLY - see https://developers.google.com/instance-id/ |
| App is running in emulator | `isEmulator()` | true | if app is running in emulator return true | | App is running in emulator | `isEmulator()` | true | if app is running in emulator return true |
| App is running on a tablet | `isTablet()` | true | if app is running on a tablet return true | | App is running on a tablet | `isTablet()` | true | if app is running on a tablet return true |
| PIN or fingerprint set | `isPinOrFingerprintSet()(callback)`| | Only supported in Android and iOS 9.0 and above | | PIN or fingerprint set | `isPinOrFingerprintSet()(callback)`| | Only supported in Android and iOS 9.0 and above
| Phone Number | `getPhoneNumber()` | "2348675309" or "" or null | Only supported in Android
| First Install Time | `getFirstInstallTime()` | 1505607068808 | Only supported in Android |
| Last Install Time | `getLastUpdateTime()` | 1505607068808 | Only supported in Android |
| App Name | `getApplicationName()` | Learnium Mobile | | | App Name | `getApplicationName()` | Learnium Mobile | |
Since the device setting for PIN/Fingerprint can be modified while the app is still open, this is available via callback instead of as a constant. To use, pass a callback function to the returned bridge function in your javascript: Since the device setting for PIN/Fingerprint can be modified while the app is still open, this is available via callback instead of as a constant. To use, pass a callback function to the returned bridge function in your javascript:
```js ```js
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
/* Begin PBXBuildFile section */ /* Begin PBXBuildFile section */
76E65CA41D4CA143009B7AF1 /* DeviceUID.m in Sources */ = {isa = PBXBuildFile; fileRef = 76E65CA31D4CA143009B7AF1 /* DeviceUID.m */; }; 76E65CA41D4CA143009B7AF1 /* DeviceUID.m in Sources */ = {isa = PBXBuildFile; fileRef = 76E65CA31D4CA143009B7AF1 /* DeviceUID.m */; };
BF770A3D1F6A3EEE007E5F09 /* DeviceUID.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = 76E65CA21D4CA143009B7AF1 /* DeviceUID.h */; };
DA5891DC1BA9A9FC002B4DB2 /* RNDeviceInfo.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = DA5891DB1BA9A9FC002B4DB2 /* RNDeviceInfo.h */; }; DA5891DC1BA9A9FC002B4DB2 /* RNDeviceInfo.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = DA5891DB1BA9A9FC002B4DB2 /* RNDeviceInfo.h */; };
DA5891DE1BA9A9FC002B4DB2 /* RNDeviceInfo.m in Sources */ = {isa = PBXBuildFile; fileRef = DA5891DD1BA9A9FC002B4DB2 /* RNDeviceInfo.m */; }; DA5891DE1BA9A9FC002B4DB2 /* RNDeviceInfo.m in Sources */ = {isa = PBXBuildFile; fileRef = DA5891DD1BA9A9FC002B4DB2 /* RNDeviceInfo.m */; };
/* End PBXBuildFile section */ /* End PBXBuildFile section */
...@@ -19,6 +20,7 @@ ...@@ -19,6 +20,7 @@
dstPath = "include/$(PRODUCT_NAME)"; dstPath = "include/$(PRODUCT_NAME)";
dstSubfolderSpec = 16; dstSubfolderSpec = 16;
files = ( files = (
BF770A3D1F6A3EEE007E5F09 /* DeviceUID.h in CopyFiles */,
DA5891DC1BA9A9FC002B4DB2 /* RNDeviceInfo.h in CopyFiles */, DA5891DC1BA9A9FC002B4DB2 /* RNDeviceInfo.h in CopyFiles */,
); );
runOnlyForDeploymentPostprocessing = 0; runOnlyForDeploymentPostprocessing = 0;
...@@ -222,7 +224,7 @@ ...@@ -222,7 +224,7 @@
"$(SRCROOT)/../../React/**", "$(SRCROOT)/../../React/**",
"$(SRCROOT)/node_modules/react-native/React/**", "$(SRCROOT)/node_modules/react-native/React/**",
"$(SRCROOT)/../react-native/React/**", "$(SRCROOT)/../react-native/React/**",
"$(SRCROOT)/../../../node_modules/react-native/React/**" "$(SRCROOT)/../../../node_modules/react-native/React/**",
); );
IPHONEOS_DEPLOYMENT_TARGET = 8.0; IPHONEOS_DEPLOYMENT_TARGET = 8.0;
OTHER_LDFLAGS = "-ObjC"; OTHER_LDFLAGS = "-ObjC";
...@@ -240,7 +242,7 @@ ...@@ -240,7 +242,7 @@
"$(SRCROOT)/../../React/**", "$(SRCROOT)/../../React/**",
"$(SRCROOT)/node_modules/react-native/React/**", "$(SRCROOT)/node_modules/react-native/React/**",
"$(SRCROOT)/../react-native/React/**", "$(SRCROOT)/../react-native/React/**",
"$(SRCROOT)/../../../node_modules/react-native/React/**" "$(SRCROOT)/../../../node_modules/react-native/React/**",
); );
IPHONEOS_DEPLOYMENT_TARGET = 8.0; IPHONEOS_DEPLOYMENT_TARGET = 8.0;
OTHER_LDFLAGS = "-ObjC"; OTHER_LDFLAGS = "-ObjC";
......
...@@ -9,10 +9,10 @@ ...@@ -9,10 +9,10 @@
#import <UIKit/UIKit.h> #import <UIKit/UIKit.h>
#import <sys/utsname.h> #import <sys/utsname.h>
#if __has_include("RCTBridgeModule.h") #if __has_include(<React/RCTAssert.h>)
#import "RCTBridgeModule.h" #import <React/RCTBridgeModule.h>
#else #else
#import <React/RCTBridgeModule.h> #import "RCTBridgeModule.h"
#endif #endif
@interface RNDeviceInfo : NSObject <RCTBridgeModule> @interface RNDeviceInfo : NSObject <RCTBridgeModule>
......
package com.learnium.RNDeviceInfo; package com.learnium.RNDeviceInfo;
import java.util.Arrays;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import com.facebook.react.ReactPackage; import com.facebook.react.ReactPackage;
import com.facebook.react.bridge.JavaScriptModule;
import com.facebook.react.bridge.NativeModule; import com.facebook.react.bridge.NativeModule;
import com.facebook.react.bridge.ReactApplicationContext; import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.uimanager.ViewManager; import com.facebook.react.uimanager.ViewManager;
import com.facebook.react.bridge.JavaScriptModule;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
public class RNDeviceInfo implements ReactPackage { public class RNDeviceInfo implements ReactPackage {
......
...@@ -9,6 +9,8 @@ import android.content.pm.PackageManager; ...@@ -9,6 +9,8 @@ import android.content.pm.PackageManager;
import android.content.res.Configuration; import android.content.res.Configuration;
import android.os.Build; import android.os.Build;
import android.provider.Settings.Secure; import android.provider.Settings.Secure;
import android.webkit.WebSettings;
import android.telephony.TelephonyManager;
import com.google.android.gms.iid.InstanceID; import com.google.android.gms.iid.InstanceID;
...@@ -84,6 +86,7 @@ public class RNDeviceModule extends ReactContextBaseJavaModule { ...@@ -84,6 +86,7 @@ public class RNDeviceModule extends ReactContextBaseJavaModule {
public @Nullable Map<String, Object> getConstants() { public @Nullable Map<String, Object> getConstants() {
HashMap<String, Object> constants = new HashMap<String, Object>(); HashMap<String, Object> constants = new HashMap<String, Object>();
TelephonyManager telMgr = (TelephonyManager) this.reactContext.getSystemService(Context.TELEPHONY_SERVICE);
PackageManager packageManager = this.reactContext.getPackageManager(); PackageManager packageManager = this.reactContext.getPackageManager();
String packageName = this.reactContext.getPackageName(); String packageName = this.reactContext.getPackageName();
String applicationName = this.reactContext.getApplicationInfo().loadLabel(this.reactContext.getPackageManager()).toString(); String applicationName = this.reactContext.getApplicationInfo().loadLabel(this.reactContext.getPackageManager()).toString();
...@@ -95,9 +98,11 @@ public class RNDeviceModule extends ReactContextBaseJavaModule { ...@@ -95,9 +98,11 @@ public class RNDeviceModule extends ReactContextBaseJavaModule {
try { try {
PackageInfo packageInfo = packageManager.getPackageInfo(packageName, 0); PackageInfo packageInfo = packageManager.getPackageInfo(packageName, 0);
ApplicationInfo applicationInfo = packageManager.getApplicationInfo(packageName, 0); PackageInfo info = packageManager.getPackageInfo(packageName, 0);
constants.put("appVersion", packageInfo.versionName); constants.put("appVersion", info.versionName);
constants.put("buildNumber", packageInfo.versionCode); constants.put("buildNumber", info.versionCode);
constants.put("firstInstallTime", info.firstInstallTime);
constants.put("lastUpdateTime", info.lastUpdateTime);
constants.put("appName", packageManager.getApplicationLabel(applicationInfo).toString()); constants.put("appName", packageManager.getApplicationLabel(applicationInfo).toString());
} catch (PackageManager.NameNotFoundException e) { } catch (PackageManager.NameNotFoundException e) {
e.printStackTrace(); e.printStackTrace();
...@@ -126,10 +131,11 @@ public class RNDeviceModule extends ReactContextBaseJavaModule { ...@@ -126,10 +131,11 @@ public class RNDeviceModule extends ReactContextBaseJavaModule {
constants.put("uniqueId", Secure.getString(this.reactContext.getContentResolver(), Secure.ANDROID_ID)); constants.put("uniqueId", Secure.getString(this.reactContext.getContentResolver(), Secure.ANDROID_ID));
constants.put("systemManufacturer", Build.MANUFACTURER); constants.put("systemManufacturer", Build.MANUFACTURER);
constants.put("bundleId", packageName); constants.put("bundleId", packageName);
constants.put("userAgent", System.getProperty("http.agent")); constants.put("userAgent", WebSettings.getDefaultUserAgent(this.reactContext));
constants.put("timezone", TimeZone.getDefault().getID()); constants.put("timezone", TimeZone.getDefault().getID());
constants.put("isEmulator", this.isEmulator()); constants.put("isEmulator", this.isEmulator());
constants.put("isTablet", this.isTablet()); constants.put("isTablet", this.isTablet());
constants.put("phoneNumber", telMgr.getLine1Number());
return constants; return constants;
} }
} }
// should be imported this way: // should be imported this way:
// import DeviceInfo from 'react-native-device-info'; // import * as DeviceInfo from 'react-native-device-info';
declare class DeviceInfo { export function getUniqueID(): string;
public static getUniqueID(): string; export function getManufacturer(): string;
public static getManufacturer(): string; export function getBrand(): string;
public static getBrand(): string; export function getModel(): string;
public static getModel(): string; export function getDeviceId(): string;
public static getDeviceId(): string; export function getSystemName(): string;
public static getSystemName(): string; export function getSystemVersion(): string;
public static getSystemVersion(): string; export function getBundleId(): string;
public static getBundleId(): string; export function getApplicationName(): string;
public static getApplicationName(): string; export function getBuildNumber(): string;
public static getBuildNumber(): string; export function getVersion(): string;
public static getVersion(): string; export function getReadableVersion(): string;
public static getReadableVersion(): string; export function getDeviceName(): string;
public static getDeviceName(): string; export function getUserAgent(): string;
public static getUserAgent(): string; export function getDeviceLocale(): string;
public static getDeviceLocale(): string; export function getDeviceCountry(): string;
public static getDeviceCountry(): string; export function getTimezone(): string;
public static getTimezone(): string; export function getInstanceID(): string;
public static getInstanceID(): string; export function isEmulator(): boolean;
public static isEmulator(): boolean; export function isTablet(): boolean;
public static isTablet(): boolean; export function isPinOrFingerprintSet(): (cb: (isPinOrFingerprintSet: boolean) => void) => void;
public static isPinOrFingerprintSet(): (cb: (isPinOrFingerprintSet: boolean) => void) => void; export function getFirstInstallTime(): number;
} export function getLastUpdateTime(): number;
export default DeviceInfo;
...@@ -68,4 +68,11 @@ module.exports = { ...@@ -68,4 +68,11 @@ module.exports = {
isPinOrFingerprintSet: function () { isPinOrFingerprintSet: function () {
return RNDeviceInfo.isPinOrFingerprintSet; return RNDeviceInfo.isPinOrFingerprintSet;
}, },
getFirstInstallTime: function () {
return RNDeviceInfo.firstInstallTime;
},
getLastUpdateTime: function () {
return RNDeviceInfo.lastUpdateTime;
},
getPhoneNumber: _ => RNDeviceInfo.phoneNumber
}; };
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment