Commit 40e1b51c authored by Gant Laborde's avatar Gant Laborde Committed by GitHub

Merge pull request #225 from douglasjunior/patch-2

Added version check and permission to work with Android API >= 16.
parents c362de2b dd9d1957
package com.learnium.RNDeviceInfo; package com.learnium.RNDeviceInfo;
import android.Manifest;
import android.app.KeyguardManager; import android.app.KeyguardManager;
import android.bluetooth.BluetoothAdapter; import android.bluetooth.BluetoothAdapter;
import android.content.Context; import android.content.Context;
...@@ -85,7 +86,6 @@ public class RNDeviceModule extends ReactContextBaseJavaModule { ...@@ -85,7 +86,6 @@ 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,11 +126,18 @@ public class RNDeviceModule extends ReactContextBaseJavaModule { ...@@ -126,11 +126,18 @@ 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", WebSettings.getDefaultUserAgent(this.reactContext)); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
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()); if (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) {
TelephonyManager telMgr = (TelephonyManager) this.reactContext.getSystemService(Context.TELEPHONY_SERVICE);
constants.put("phoneNumber", telMgr.getLine1Number());
}
return constants; return constants;
} }
} }
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