1
0
mirror of https://github.com/nerzhul/ownCloud-SMS-App.git synced 2026-08-23 14:23:04 +00:00

Crashfix when data is not available

This commit is contained in:
Loic Blot
2015-03-23 20:17:30 +01:00
parent 1a0e887179
commit 58b9ed61ff
3 changed files with 30 additions and 23 deletions
@@ -12,36 +12,39 @@ package fr.unix_experience.owncloud_sms.engine;
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
*
* You should have received a copy of the GNU Affero General Public License
*/
*/
import fr.unix_experience.owncloud_sms.prefs.OCSMSSharedPrefs;
import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.telephony.TelephonyManager;
import fr.unix_experience.owncloud_sms.prefs.OCSMSSharedPrefs;
public class ConnectivityMonitor {
public ConnectivityMonitor(Context context) {
public ConnectivityMonitor(final Context context) {
_context = context;
}
// Valid connection = WiFi or Mobile data
public boolean isValid() {
if (_cMgr == null) {
_cMgr = (ConnectivityManager) _context.getSystemService(Context.CONNECTIVITY_SERVICE);
}
}
final android.net.NetworkInfo niWiFi = _cMgr.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
final android.net.NetworkInfo niMobile = _cMgr.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
if (niWiFi.isAvailable() || niMobile.isAvailable()) {
// Load the connectivity manager to determine on which network we are connected
NetworkInfo netInfo = _cMgr.getActiveNetworkInfo();
OCSMSSharedPrefs prefs = new OCSMSSharedPrefs(_context);
final NetworkInfo netInfo = _cMgr.getActiveNetworkInfo();
if (netInfo == null) {
return false;
}
final OCSMSSharedPrefs prefs = new OCSMSSharedPrefs(_context);
// Check
switch (netInfo.getType()) {
case ConnectivityManager.TYPE_WIFI:
@@ -58,7 +61,7 @@ public class ConnectivityMonitor {
case TelephonyManager.NETWORK_TYPE_HSDPA:
case TelephonyManager.NETWORK_TYPE_HSPA:
case TelephonyManager.NETWORK_TYPE_HSUPA:
case TelephonyManager.NETWORK_TYPE_UMTS:
case TelephonyManager.NETWORK_TYPE_UMTS:
case TelephonyManager.NETWORK_TYPE_EHRPD:
case TelephonyManager.NETWORK_TYPE_EVDO_B:
case TelephonyManager.NETWORK_TYPE_HSPAP:
@@ -71,13 +74,11 @@ public class ConnectivityMonitor {
default:
return prefs.syncInOtherModes();
}
}
return false;
}
private ConnectivityManager _cMgr;
private Context _context;
private final Context _context;
}