skip to Main Content

I am developing a flutter application where I need to check internet connection. But it is working fine for rest of the device except Samsung s23, Galaxy Z Fold5. I am checking the release apk, and do not have any real device access for this I could get any debug result.

In AndroidManifest, I have taken this permission:

<uses-permission android:name="android.permission.INTERNET" />

Here is the code, for checking for an internet connection:

final result = await InternetAddress.lookup('example.com');

try {
    if (result.isNotEmpty && result[0].rawAddress.isNotEmpty) {
        Get.snackbar('Internet', 'Navigate to Internet');
    } else {
        Get.snackbar('No Internet', 'Navigate to No Internet');
    }
} on SocketException catch (_) {
    Get.snackbar('No Internet', 'SocketException');
}

In release mode, it always shows the snackbar from the exception. I need to show the ‘Navigate to Internet’ snackbar.

Can I get any solution?

2

Answers


  1. It seems like you are encountering an issue with checking the internet connection in your Flutter application specifically on Samsung S23 and Galaxy Z Fold5 devices when using the release APK. Here are a few suggestions to help you troubleshoot and potentially resolve the issue:

    1. Network Security Configuration:

      • Check if the Samsung S23 and Galaxy Z Fold5 devices have any specific network security configurations that could be affecting the internet connectivity check in the release APK. Some devices may have stricter network security settings that could impact network-related operations.
    2. Network Permission:

      • Ensure that the network permission is being granted correctly on the Samsung S23 and Galaxy Z Fold5 devices for the release APK. It’s possible that the release APK may require additional permissions or specific configurations to access the internet on these devices.
    3. Network Connectivity Check:

      • Instead of using the InternetAddress.lookup method, try using the Connectivity package in Flutter to check the network connectivity status. This package provides more comprehensive network connectivity checks and can handle various scenarios more effectively.
    4. Network Configuration:

      • Check if there are any specific network configurations, such as proxy settings or custom DNS configurations, on the Samsung S23 and Galaxy Z Fold5 devices that could be affecting the network connectivity check in the release APK.
    5. Test on Real Devices:

      • If possible, try to test the release APK on real Samsung S23 and Galaxy Z Fold5 devices to see if the issue persists. Real device testing can provide more accurate insights into the specific behavior of the application on these devices.
    6. Error Logging:

      • Implement error logging within the application to capture any specific error messages or exceptions that occur during the network connectivity check on the Samsung S23 and Galaxy Z Fold5 devices. This can help in diagnosing the root cause of the issue.

    Please note that without access to the real devices for debugging, it may be challenging to pinpoint the exact cause of the issue. If possible, consider reaching out to users who have the Samsung S23 and Galaxy Z Fold5 devices to gather more information about their experience with the release APK.

    By considering these suggestions and potentially testing on real devices, you may be able to identify the specific factors contributing to the issue and find a solution to ensure accurate internet connectivity checks on the Samsung S23 and Galaxy Z Fold5 devices.

    Login or Signup to reply.
  2. It seems there is an issue in the Dart SDK for it. It was closed without a fix.

    One suggestion there is to use the internet_connection_checker_plus package, which seems to do exactly what you’re trying to achieve.

    To use it, add the following to your pubspec.yaml:

    dependencies:
      internet_connection_checker_plus: ^2.1.0
    

    And change your code to use it:

    final hasInternet = await InternetConnection().hasInternetAccess;
    
    if (hasInternet) {
        Get.snackbar('Internet', 'Navigate to Internet');
    } else {
        Get.snackbar('No Internet', 'Navigate to No Internet');
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search