Feature #221
Utiliser le ConnectitManager
Added by Frédéric Barthéléry almost 15 years ago.
Updated over 14 years ago.
Description
Ca serait bien d'utiliser le ConnectivityManager du telephone afin de savoir si on acces ou non a une connexion, avant de lancer une tentative inutile.
Usefull Links :¶
Petit exemple d'un autre projet ...
public static boolean isWifi() {
WifiManager wm = (WifiManager) mContext
.getSystemService(Context.WIFI_SERVICE);
WifiInfo wi = wm.getConnectionInfo();
if (wi != null)
Log.i("SipUA:", "isFast() "
+ WifiInfo.getDetailedStateOf(wi.getSupplicantState())
+ " " + cellAsu);
if (wi != null
&& (WifiInfo.getDetailedStateOf(wi.getSupplicantState()) == DetailedState.OBTAINING_IPADDR || WifiInfo
.getDetailedStateOf(wi.getSupplicantState()) == DetailedState.CONNECTED)) {
on_wlan = PreferenceManager.getDefaultSharedPreferences(mContext)
.getBoolean("wlan", false);
return on_wlan;
}
on_wlan = false;
return on_wlan;
}
public static boolean isUmts() {
TelephonyManager tm = (TelephonyManager) mContext
.getSystemService(Context.TELEPHONY_SERVICE);
if (!PreferenceManager.getDefaultSharedPreferences(mContext)
.getBoolean("3g", false))
return false;
if (tm.getNetworkType() >= TelephonyManager.NETWORK_TYPE_UMTS)
return true;
return false;
}
public static boolean isEdge() {
TelephonyManager tm = (TelephonyManager) mContext
.getSystemService(Context.TELEPHONY_SERVICE);
if (tm.getNetworkType() == TelephonyManager.NETWORK_TYPE_EDGE)
return cellAsu >= minEdge;
return false;
}
Nikita Kozlov wrote:
Petit exemple d'un autre projet ...
[...]
Peut etre enormement simplifier vu que nous on veut juste savoir si il y a du reseau.
yep, c'était juste un bref copier/coller.
- Assignee set to Nikita Kozlov
- Status changed from New to Feedback
- % Done changed from 0 to 100
- File installsamba4.sh added
- File deleted (
installsamba4.sh)
- % Done changed from 100 to 90
Je pense que ca devrait plutot etre fait dans le service et non dans l'ui.
- % Done changed from 90 to 100
Add of an Intent receiver in the service.
- Status changed from Feedback to Closed
- Target version changed from 0.2 to 0.1.3
Also available in: Atom
PDF