Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use ConnectivityManager instead of ConnectivityManagerCompat #509

Merged
merged 7 commits into from
Oct 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
22 changes: 0 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,22 +45,6 @@ Linking the package manually is not required anymore with [Autolinking](https://
}
```

- **Android Platform with AndroidX:**

Modify your **android/build.gradle** configuration:
```
buildscript {
ext {
buildToolsVersion = "28.0.3"
minSdkVersion = 16
compileSdkVersion = 28
targetSdkVersion = 28
# Remove 'supportLibVersion' property and put specific versions for AndroidX libraries
androidXCore = "1.0.2"
// Put here other AndroidX dependencies
}
```

- **macOS Platform:**

Autolinking is not yet available on macOS. See the [Manual linking steps for macOS](#manual-linking-macos) below.
Expand Down Expand Up @@ -426,12 +410,6 @@ NetInfo.fetch("wifi").then(state => {

### Errors when building on Android

This library was migrated from using the support library to AndroidX in version `4.0.0`. All of your depenencies must be using either the support library *or* AndroidX. Using a mixture of the two is not possible.

From React Native 0.60 AndroidX is used by default.

If you need to either convert this library back to the support library (to use an older React Native version) or convert other libraries forward to use AndroidX (if they have not been updated yet), you can use the [Jetifier](https://github.com/mikehardy/jetifier) tool.
mikehardy marked this conversation as resolved.
Show resolved Hide resolved

### Errors while running Jest tests

If you do not have a Jest Setup file configured, you should add the following to your Jest settings and create the `jest.setup.js` file in project root:
Expand Down
14 changes: 1 addition & 13 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ buildscript {
}

dependencies {
classpath("com.android.tools.build:gradle:3.6.3")
classpath("com.android.tools.build:gradle:4.2.2")
}
}
}
Expand Down Expand Up @@ -54,16 +54,4 @@ dependencies {
//noinspection GradleDynamicVersion
implementation 'com.facebook.react:react-native:+'

def supportLibVersion = getExtOrInitialValue('supportLibVersion', getExtOrInitialValue('supportVersion', null))
def androidXVersion = getExtOrInitialValue('androidXVersion', null)
def androidXCore = getExtOrInitialValue('androidXCore', null)
if (supportLibVersion && androidXVersion == null && androidXCore == null) {
implementation "com.android.support:appcompat-v7:$supportLibVersion"
} else {
def defaultAndroidXVersion = "1.3.2"
if (androidXCore == null) {
androidXCore = androidXVersion == null ? defaultAndroidXVersion : androidXVersion
}
implementation "androidx.core:core:$androidXCore"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
@SuppressWarnings("deprecation")
public class BroadcastReceiverConnectivityReceiver extends ConnectivityReceiver {
private final ConnectivityBroadcastReceiver mConnectivityBroadcastReceiver;
public static final String CONNECTIVITY_ACTION = "android.net.conn.CONNECTIVITY_CHANGE";

public BroadcastReceiverConnectivityReceiver(ReactApplicationContext reactContext) {
super(reactContext);
Expand All @@ -37,7 +38,7 @@ public BroadcastReceiverConnectivityReceiver(ReactApplicationContext reactContex
@Override
public void register() {
IntentFilter filter = new IntentFilter();
filter.addAction(ConnectivityManager.CONNECTIVITY_ACTION);
filter.addAction(CONNECTIVITY_ACTION);
getReactContext().registerReceiver(mConnectivityBroadcastReceiver, filter);
mConnectivityBroadcastReceiver.setRegistered(true);
updateAndSendConnectionType();
Expand Down Expand Up @@ -117,7 +118,7 @@ public boolean isRegistered() {
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if (action != null && action.equals(ConnectivityManager.CONNECTIVITY_ACTION)) {
if (action != null && action.equals(CONNECTIVITY_ACTION)) {
updateAndSendConnectionType();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
import android.net.wifi.WifiManager;
import android.telephony.TelephonyManager;

import androidx.core.net.ConnectivityManagerCompat;

import com.facebook.react.bridge.Arguments;
import com.facebook.react.bridge.Promise;
import com.facebook.react.bridge.ReactApplicationContext;
Expand Down Expand Up @@ -136,7 +134,7 @@ private WritableMap createConnectivityEventMap(@Nullable final String requestedI
WritableMap details = createDetailsMap(detailsInterface);
if (isConnected) {
boolean isConnectionExpensive =
ConnectivityManagerCompat.isActiveNetworkMetered(getConnectivityManager());
getConnectivityManager() == null ? true : getConnectivityManager().isActiveNetworkMetered();
details.putBoolean("isConnectionExpensive", isConnectionExpensive);
}
event.putMap("details", details);
Expand Down