From fbb17b65f556edd963da004b1202b91e2de074b4 Mon Sep 17 00:00:00 2001 From: rizzomichaelg Date: Wed, 11 Oct 2017 09:34:42 -0500 Subject: [PATCH 1/2] Check for null with getCurrentActivity() getCurrentActivity() occasionally returns null --- .../main/java/com/learnium/RNDeviceInfo/RNDeviceModule.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/android/src/main/java/com/learnium/RNDeviceInfo/RNDeviceModule.java b/android/src/main/java/com/learnium/RNDeviceInfo/RNDeviceModule.java index a80671dd4..eed7325bb 100644 --- a/android/src/main/java/com/learnium/RNDeviceInfo/RNDeviceModule.java +++ b/android/src/main/java/com/learnium/RNDeviceInfo/RNDeviceModule.java @@ -157,9 +157,10 @@ public void getMacAddress(Promise p) { constants.put("timezone", TimeZone.getDefault().getID()); constants.put("isEmulator", this.isEmulator()); constants.put("isTablet", this.isTablet()); - if (getCurrentActivity().checkCallingOrSelfPermission(Manifest.permission.READ_PHONE_STATE) == PackageManager.PERMISSION_GRANTED || + if (getCurrentActivity() != null && + (getCurrentActivity().checkCallingOrSelfPermission(Manifest.permission.READ_PHONE_STATE) == PackageManager.PERMISSION_GRANTED || getCurrentActivity().checkCallingOrSelfPermission(Manifest.permission.READ_SMS) == PackageManager.PERMISSION_GRANTED || - getCurrentActivity().checkCallingOrSelfPermission("android.permission.READ_PHONE_NUMBERS") == PackageManager.PERMISSION_GRANTED) { + getCurrentActivity().checkCallingOrSelfPermission("android.permission.READ_PHONE_NUMBERS") == PackageManager.PERMISSION_GRANTED)) { TelephonyManager telMgr = (TelephonyManager) this.reactContext.getSystemService(Context.TELEPHONY_SERVICE); constants.put("phoneNumber", telMgr.getLine1Number()); } From 1968f8024e6c2f511f8ca063db32de477a03c1d3 Mon Sep 17 00:00:00 2001 From: rizzomichaelg Date: Wed, 11 Oct 2017 09:49:53 -0500 Subject: [PATCH 2/2] Update CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index bef9fcda2..8a7d48899 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ - Add Android support for serial number, IP, and MAC address (https://github.com/rebeccahughes/react-native-device-info/pull/150) - Add tvOS support (https://github.com/rebeccahughes/react-native-device-info/pull/235) - Add flow types +- Fix getCurrentActivity() null crash in Android (https://github.com/rebeccahughes/react-native-device-info/pull/247) [Diff](https://github.com/rebeccahughes/react-native-device-info/compare/1aafc6f0b20d7cd6f0939ea5370e9899e4914c93...master)