Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions packages/connectivity_plus/connectivity_plus/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 2.0.1

- Upgrade Android compile SDK version
- Several code improvements

## 2.0.0

- Remove deprecated method `registerWith` (of Android v1 embedding)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
group 'io.flutter.plugins.connectivity'
version '1.0-SNAPSHOT'
def args = ["-Xlint:deprecation","-Xlint:unchecked","-Werror"]

buildscript {
repositories {
Expand All @@ -9,7 +8,7 @@ buildscript {
}

dependencies {
classpath 'com.android.tools.build:gradle:3.5.0'
classpath 'com.android.tools.build:gradle:7.0.2'
}
}

Expand All @@ -23,12 +22,7 @@ rootProject.allprojects {
apply plugin: 'com.android.library'

android {
compileSdkVersion 29

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
compileSdkVersion 31

defaultConfig {
minSdkVersion 16
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class Connectivity {
static final String CONNECTIVITY_WIFI = "wifi";
static final String CONNECTIVITY_MOBILE = "mobile";
static final String CONNECTIVITY_ETHERNET = "ethernet";
private ConnectivityManager connectivityManager;
private final ConnectivityManager connectivityManager;

public Connectivity(ConnectivityManager connectivityManager) {
this.connectivityManager = connectivityManager;
Expand Down Expand Up @@ -44,24 +44,24 @@ String getNetworkType() {

@SuppressWarnings("deprecation")
private String getNetworkTypeLegacy() {
// handle type for Android versions less than Android 9
// handle type for Android versions less than Android 6
android.net.NetworkInfo info = connectivityManager.getActiveNetworkInfo();
if (info == null || !info.isConnected()) {
return "none";
return CONNECTIVITY_NONE;
}
int type = info.getType();
switch (type) {
case ConnectivityManager.TYPE_ETHERNET:
return "ethernet";
return CONNECTIVITY_ETHERNET;
case ConnectivityManager.TYPE_WIFI:
case ConnectivityManager.TYPE_WIMAX:
return "wifi";
return CONNECTIVITY_WIFI;
case ConnectivityManager.TYPE_MOBILE:
case ConnectivityManager.TYPE_MOBILE_DUN:
case ConnectivityManager.TYPE_MOBILE_HIPRI:
return "mobile";
return CONNECTIVITY_MOBILE;
default:
return "none";
return CONNECTIVITY_NONE;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@
*/
public class ConnectivityBroadcastReceiver extends BroadcastReceiver
implements EventChannel.StreamHandler {
private Context context;
private Connectivity connectivity;
private final Context context;
private final Connectivity connectivity;
private EventChannel.EventSink events;
private Handler mainHandler = new Handler(Looper.getMainLooper());
private final Handler mainHandler = new Handler(Looper.getMainLooper());
private ConnectivityManager.NetworkCallback networkCallback;
public static final String CONNECTIVITY_ACTION = "android.net.conn.CONNECTIVITY_CHANGE";

Expand Down Expand Up @@ -82,29 +82,13 @@ public void onReceive(Context context, Intent intent) {
}
}

public ConnectivityManager.NetworkCallback getNetworkCallback() {
return networkCallback;
}

private void sendEvent() {
Runnable runnable =
new Runnable() {
@Override
public void run() {
events.success(connectivity.getNetworkType());
}
};
Runnable runnable = () -> events.success(connectivity.getNetworkType());
mainHandler.post(runnable);
}

private void sendEvent(final String networkType) {
Runnable runnable =
new Runnable() {
@Override
public void run() {
events.success(networkType);
}
};
Runnable runnable = () -> events.success(networkType);
mainHandler.post(runnable);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

package dev.fluttercommunity.plus.connectivity;

import androidx.annotation.NonNull;
import io.flutter.plugin.common.MethodCall;
import io.flutter.plugin.common.MethodChannel;

Expand All @@ -14,7 +15,7 @@
*/
class ConnectivityMethodChannelHandler implements MethodChannel.MethodCallHandler {

private Connectivity connectivity;
private final Connectivity connectivity;

/**
* Construct the ConnectivityMethodChannelHandler with a {@code connectivity}. The {@code
Expand All @@ -26,14 +27,11 @@ class ConnectivityMethodChannelHandler implements MethodChannel.MethodCallHandle
}

@Override
public void onMethodCall(MethodCall call, MethodChannel.Result result) {
switch (call.method) {
case "check":
result.success(connectivity.getNetworkType());
break;
default:
result.notImplemented();
break;
public void onMethodCall(MethodCall call, @NonNull MethodChannel.Result result) {
if ("check".equals(call.method)) {
result.success(connectivity.getNetworkType());
} else {
result.notImplemented();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import android.content.Context;
import android.net.ConnectivityManager;
import androidx.annotation.NonNull;
import io.flutter.embedding.engine.plugins.FlutterPlugin;
import io.flutter.plugin.common.BinaryMessenger;
import io.flutter.plugin.common.EventChannel;
Expand All @@ -24,7 +25,7 @@ public void onAttachedToEngine(FlutterPluginBinding binding) {
}

@Override
public void onDetachedFromEngine(FlutterPluginBinding binding) {
public void onDetachedFromEngine(@NonNull FlutterPluginBinding binding) {
teardownChannels();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ apply plugin: 'com.android.application'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"

android {
compileSdkVersion 28
compileSdkVersion 31

lintOptions {
disable 'InvalidPackage'
Expand All @@ -34,7 +34,7 @@ android {
defaultConfig {
applicationId "io.flutter.plugins.connectivityexample"
minSdkVersion 16
targetSdkVersion 28
targetSdkVersion 31
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
Expand All @@ -52,7 +52,7 @@ flutter {
}

dependencies {
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test:runner:1.4.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,12 @@
<uses-permission android:name="android.permission.INTERNET"/>

<application android:name="io.flutter.app.FlutterApplication" android:label="connectivity_example" android:icon="@mipmap/ic_launcher">
<activity android:name=".EmbeddingV1Activity"
android:launchMode="singleTop"
android:theme="@android:style/Theme.Black.NoTitleBar"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|layoutDirection"
android:hardwareAccelerated="true"
android:exported="true"
android:windowSoftInputMode="adjustResize">
</activity>
<activity android:name="io.flutter.embedding.android.FlutterActivity"
android:theme="@android:style/Theme.Black.NoTitleBar"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|layoutDirection"
android:hardwareAccelerated="true"
android:windowSoftInputMode="adjustResize">
android:windowSoftInputMode="adjustResize"
android:exported="true">

<intent-filter>
<action android:name="android.intent.action.MAIN"/>
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ buildscript {
}

dependencies {
classpath 'com.android.tools.build:gradle:4.2.0'
classpath 'com.android.tools.build:gradle:7.0.2'
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
org.gradle.jvmargs=-Xmx1536M
android.useAndroidX=true
android.enableJetifier=true
android.enableR8=true
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#Tue Oct 05 14:43:11 CEST 2021
distributionBase=GRADLE_USER_HOME
distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-bin.zip
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.7.1-all.zip
zipStoreBase=GRADLE_USER_HOME
2 changes: 1 addition & 1 deletion packages/connectivity_plus/connectivity_plus/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: connectivity_plus
description: Flutter plugin for discovering the state of the network (WiFi & mobile/cellular) connectivity on Android and iOS.
version: 2.0.0
version: 2.0.1
homepage: https://plus.fluttercommunity.dev/
repository: https://github.com/fluttercommunity/plus_plugins/tree/main/packages/

Expand Down