From 38b7415ddeb535725ab270b2b69d09fc71cbbab0 Mon Sep 17 00:00:00 2001 From: M66B Date: Thu, 7 May 2020 12:23:19 +0200 Subject: [PATCH] Second try get active network --- .../eu/faircode/email/ConnectionHelper.java | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/ConnectionHelper.java b/app/src/main/java/eu/faircode/email/ConnectionHelper.java index 33d9776c13..2dfbf0805e 100644 --- a/app/src/main/java/eu/faircode/email/ConnectionHelper.java +++ b/app/src/main/java/eu/faircode/email/ConnectionHelper.java @@ -186,17 +186,16 @@ public class ConnectionHelper { if (cm == null) return null; - if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.M) { - NetworkInfo ani = cm.getActiveNetworkInfo(); - if (ani == null || !ani.isConnected()) - return null; - return cm.isActiveNetworkMetered(); - } - - Network active = cm.getActiveNetwork(); + Network active = null; + if (Build.VERSION.SDK_INT > Build.VERSION_CODES.M) + active = cm.getActiveNetwork(); if (active == null) { - Log.i("isMetered: no active network"); - return null; + NetworkInfo ani = cm.getActiveNetworkInfo(); + if (ani == null || !ani.isConnected()) { + Log.i("isMetered: no active network info=" + ani); + return null; + } + return cm.isActiveNetworkMetered(); } // onLost [... state: DISCONNECTED/DISCONNECTED ... available: true]