|
6 | 6 | */
|
7 | 7 | package com.reactnativecommunity.netinfo;
|
8 | 8 |
|
9 |
| -import android.Manifest; |
10 | 9 | import android.content.Context;
|
11 |
| -import android.content.pm.PackageManager; |
12 | 10 | import android.net.ConnectivityManager;
|
13 | 11 | import android.net.wifi.WifiInfo;
|
14 | 12 | import android.net.wifi.WifiManager;
|
15 | 13 | import android.telephony.TelephonyManager;
|
16 | 14 |
|
17 |
| -import androidx.core.content.ContextCompat; |
18 | 15 | import androidx.core.net.ConnectivityManagerCompat;
|
19 | 16 |
|
20 | 17 | import com.facebook.react.bridge.Arguments;
|
@@ -115,8 +112,10 @@ private WritableMap createConnectivityEventMap(@Nullable final String requestedI
|
115 | 112 | WritableMap event = Arguments.createMap();
|
116 | 113 |
|
117 | 114 | // Add if WiFi is ON or OFF
|
118 |
| - boolean isEnabled = mWifiManager.isWifiEnabled(); |
119 |
| - event.putBoolean("isWifiEnabled", isEnabled); |
| 115 | + if (NetInfoUtils.isAccessWifiStatePermissionGranted(getReactContext())) { |
| 116 | + boolean isEnabled = mWifiManager.isWifiEnabled(); |
| 117 | + event.putBoolean("isWifiEnabled", isEnabled); |
| 118 | + } |
120 | 119 |
|
121 | 120 | // Add the connection type information
|
122 | 121 | event.putString("type", requestedInterface != null ? requestedInterface : mConnectionType.label);
|
@@ -161,8 +160,7 @@ private WritableMap createDetailsMap(@Nonnull String detailsInterface) {
|
161 | 160 | }
|
162 | 161 | break;
|
163 | 162 | case "wifi":
|
164 |
| - if (ContextCompat.checkSelfPermission(getReactContext(), |
165 |
| - Manifest.permission.ACCESS_WIFI_STATE) == PackageManager.PERMISSION_GRANTED) { |
| 163 | + if (NetInfoUtils.isAccessWifiStatePermissionGranted(getReactContext())) { |
166 | 164 | WifiInfo wifiInfo = mWifiManager.getConnectionInfo();
|
167 | 165 | if (wifiInfo != null) {
|
168 | 166 | // Get the SSID
|
|
0 commit comments