src/com/beem/project/beem/utils/BeemConnectivity.java
changeset 1044 197a85a35cba
parent 1043 7d6f2526244a
child 1045 e5a970600066
equal deleted inserted replaced
1043:7d6f2526244a 1044:197a85a35cba
     1 /*
       
     2     BEEM is a videoconference application on the Android Platform.
       
     3 
       
     4     Copyright (C) 2009 by Frederic-Charles Barthelery,
       
     5                           Jean-Manuel Da Silva,
       
     6                           Nikita Kozlov,
       
     7                           Philippe Lago,
       
     8                           Jean Baptiste Vergely,
       
     9                           Vincent Veronis.
       
    10 
       
    11     This file is part of BEEM.
       
    12 
       
    13     BEEM is free software: you can redistribute it and/or modify
       
    14     it under the terms of the GNU General Public License as published by
       
    15     the Free Software Foundation, either version 3 of the License, or
       
    16     (at your option) any later version.
       
    17 
       
    18     BEEM is distributed in the hope that it will be useful,
       
    19     but WITHOUT ANY WARRANTY; without even the implied warranty of
       
    20     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
       
    21     GNU General Public License for more details.
       
    22 
       
    23     You should have received a copy of the GNU General Public License
       
    24     along with BEEM.  If not, see <http://www.gnu.org/licenses/>.
       
    25 
       
    26     Please send bug reports with examples or suggestions to
       
    27     contact@beem-project.com or http://dev.beem-project.com/
       
    28 
       
    29     Epitech, hereby disclaims all copyright interest in the program "Beem"
       
    30     written by Frederic-Charles Barthelery,
       
    31                Jean-Manuel Da Silva,
       
    32                Nikita Kozlov,
       
    33                Philippe Lago,
       
    34                Jean Baptiste Vergely,
       
    35                Vincent Veronis.
       
    36 
       
    37     Nicolas Sadirac, November 26, 2009
       
    38     President of Epitech.
       
    39 
       
    40     Flavien Astraud, November 26, 2009
       
    41     Head of the EIP Laboratory.
       
    42 
       
    43 */
       
    44 package com.beem.project.beem.utils;
       
    45 
       
    46 import android.content.Context;
       
    47 import android.net.ConnectivityManager;
       
    48 import android.net.NetworkInfo;
       
    49 import android.net.NetworkInfo.DetailedState;
       
    50 import android.net.wifi.WifiInfo;
       
    51 import android.net.wifi.WifiManager;
       
    52 import android.telephony.TelephonyManager;
       
    53 
       
    54 /**
       
    55  * The Class BeemConnectivity.
       
    56  */
       
    57 public final class BeemConnectivity {
       
    58 
       
    59     /**
       
    60      * Private constructor to forbid instantiation.
       
    61      */
       
    62     private BeemConnectivity() { }
       
    63 
       
    64     /**
       
    65      * Checks if is connected.
       
    66      * @param ctx the ctx
       
    67      * @return true, if is connected
       
    68      */
       
    69     public static boolean isConnected(final Context ctx) {
       
    70 	ConnectivityManager cm = (ConnectivityManager) ctx.getSystemService(
       
    71 	    Context.CONNECTIVITY_SERVICE);
       
    72 	NetworkInfo ni = cm.getActiveNetworkInfo();
       
    73 	return ni != null && ni.isConnected();
       
    74     }
       
    75 
       
    76     /**
       
    77      * Checks if is wifi.
       
    78      * @param ctx the ctx
       
    79      * @return true, if is wifi
       
    80      */
       
    81     public static boolean isWifi(final Context ctx) {
       
    82 	WifiManager wm = (WifiManager) ctx.getSystemService(
       
    83 	    Context.WIFI_SERVICE);
       
    84 	WifiInfo wi = wm.getConnectionInfo();
       
    85 	if (wi != null
       
    86 	    && (WifiInfo.getDetailedStateOf(wi.getSupplicantState())
       
    87 		== DetailedState.OBTAINING_IPADDR
       
    88 		|| WifiInfo.getDetailedStateOf(wi.getSupplicantState())
       
    89 		== DetailedState.CONNECTED)) {
       
    90 	    return false;
       
    91 	}
       
    92 	return false;
       
    93     }
       
    94 
       
    95     /**
       
    96      * Checks if is umts.
       
    97      * @param ctx the ctx
       
    98      * @return true, if is umts
       
    99      */
       
   100     public static boolean isUmts(final Context ctx) {
       
   101 	TelephonyManager tm = (TelephonyManager) ctx.getSystemService(
       
   102 	    Context.TELEPHONY_SERVICE);
       
   103 	return tm.getNetworkType() >= TelephonyManager.NETWORK_TYPE_UMTS;
       
   104     }
       
   105 
       
   106     /**
       
   107      * Checks if is edge.
       
   108      * @param ctx the ctx
       
   109      * @return true, if is edge
       
   110      */
       
   111     public static boolean isEdge(final Context ctx) {
       
   112 	TelephonyManager tm = (TelephonyManager) ctx.getSystemService(
       
   113 	    Context.TELEPHONY_SERVICE);
       
   114 	return tm.getNetworkType() == TelephonyManager.NETWORK_TYPE_EDGE;
       
   115     }
       
   116 
       
   117 }