blob: 89f123220b1eaafe77fe65f245e957efe5c34b46 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
package com.mapswithme.util;
import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import com.mapswithme.maps.MWMApplication;
public class ConnectionState
{
// values should correspond to ones from enum class EConnectionType (in platform/platform.hpp)
private static final byte CONNECTION_NONE = 0;
private static final byte CONNECTION_WIFI = 1;
private static final byte CONNECTION_WWAN = 2;
private static boolean isNetworkConnected(int networkType)
{
final ConnectivityManager manager = (ConnectivityManager) MWMApplication.get().getSystemService(Context.CONNECTIVITY_SERVICE);
final NetworkInfo info = manager.getActiveNetworkInfo();
return info != null && info.getType() == networkType && info.isConnected();
}
public static boolean is3gConnected()
{
return isNetworkConnected(ConnectivityManager.TYPE_MOBILE);
}
public static boolean isWifiConnected()
{
return isNetworkConnected(ConnectivityManager.TYPE_WIFI);
}
public static boolean isConnected()
{
return isNetworkConnected(ConnectivityManager.TYPE_WIFI) || isNetworkConnected(ConnectivityManager.TYPE_MOBILE);
}
public static byte getConnectionState()
{
if (isWifiConnected())
return CONNECTION_WIFI;
else if (is3gConnected())
return CONNECTION_WWAN;
return CONNECTION_NONE;
}
}
|