Commit 7c299f1f authored by Gant Laborde's avatar Gant Laborde Committed by GitHub

Merge pull request #174 from passabilities/phone-number

Add support for phone number.
parents ce93f5c6 e599ce40
...@@ -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
...@@ -185,6 +186,7 @@ var DeviceInfo = require('react-native-device-info'); ...@@ -185,6 +186,7 @@ var DeviceInfo = require('react-native-device-info');
| 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
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:
......
...@@ -9,6 +9,7 @@ import android.content.res.Configuration; ...@@ -9,6 +9,7 @@ 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.webkit.WebSettings;
import android.telephony.TelephonyManager;
import com.google.android.gms.iid.InstanceID; import com.google.android.gms.iid.InstanceID;
...@@ -84,6 +85,7 @@ public class RNDeviceModule extends ReactContextBaseJavaModule { ...@@ -84,6 +85,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();
...@@ -126,6 +128,7 @@ public class RNDeviceModule extends ReactContextBaseJavaModule { ...@@ -126,6 +128,7 @@ public class RNDeviceModule extends ReactContextBaseJavaModule {
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;
} }
} }
...@@ -65,4 +65,5 @@ module.exports = { ...@@ -65,4 +65,5 @@ module.exports = {
isPinOrFingerprintSet: function () { isPinOrFingerprintSet: function () {
return RNDeviceInfo.isPinOrFingerprintSet; return RNDeviceInfo.isPinOrFingerprintSet;
}, },
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