martykan / forecastie

A simple, opensource weather app for Android.
Other
867 stars 335 forks source link

Compatibility issue when calling method #682

Open PSDroid2022 opened 2 years ago

PSDroid2022 commented 2 years ago

We confirm a compatibility issue which might threaten the robustness of your app and give a detailed suggestion for you.

In ''cz.martykan.forecastie.AlarmReceiver", you invoke the framework API "<android.net.ConnectivityManager: android.net.NetworkInfo getActiveNetworkInfo()>" in "isNetworkAvailable" method as shown in following. But actually, this method is deprecated after API level 29 (https://developer.android.google.cn/reference/kotlin/android/net/ConnectivityManager?hl=en#getActiveNetworkInfo()).

 private boolean isNetworkAvailable() {
        ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
        NetworkInfo activeNetworkInfo = connectivityManager.getActiveNetworkInfo();
        return activeNetworkInfo != null && activeNetworkInfo.isConnected();
    }

So when the app try to invoke this API on devices after API level 29, your app will run with an unpredictable results. So we suggest you add an "if(SDK_INT <30)" to fix this potential issue.