| |||||||
Das Thema "Verbindungsprotokoll ermitteln" befindet sich unter Android App Entwicklung auf Android-Hilfe.de.
|
| | Themen-Optionen | Ansicht |
| | #1 (permalink) |
| Neuer Benutzer Modell: Samsung Galaxy S2 (I9100) Registriert seit: 23.05.2011
Beiträge: 16
Abgegebene Danke: 4
Erhielt 0 Danke für 0 Beiträge
| wie kann ich das Verbindungsprotokoll einer bestehenden Internetverbindung ermitteln? Hintergrund ist folgender: Wenn das Gerät mit UMTS oder besser (inkl. Wi-Fi/WiMAX) verbunden ist, soll meine Anwendung eine große Bilddatei herunterladen, andernfalls nur ein Thumbnail. Bis jetzt habe ich die folgende Routine, welche prüft, ob überhaupt eine Verbindung besteht: Code: import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
public class Utils {
/** Zustand der Internetverbundung feststellen. */
public static int ConnectivityState(Context context) {
ConnectivityManager connMgr = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo mobileInfo = connMgr.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
NetworkInfo wifiInfo = connMgr.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
NetworkInfo wimaxInfo = connMgr.getNetworkInfo(ConnectivityManager.TYPE_WIMAX);
// WiMAX.
if(wimaxInfo != null && wimaxInfo.isConnected()) {
return CONN_ONLINE_WIMAX;
}
else if(wimaxInfo != null && wimaxInfo.isConnectedOrConnecting()) {
return CONN_DIALING_WIMAX;
}
// WLAN.
else if(wifiInfo != null && wifiInfo.isConnected()) {
return CONN_ONLINE_WIFI;
}
else if(wifiInfo != null && wifiInfo.isConnectedOrConnecting()) {
return CONN_DIALING_WIFI;
}
// Mobile (GPRS/UMTS/HSDPA).
else if(mobileInfo != null && mobileInfo.isConnected()) {
return CONN_ONLINE_MOBILE;
}
else if(mobileInfo != null && mobileInfo.isConnectedOrConnecting()) {
return CONN_DIALING_MOBILE;
}
// Nicht verbunden.
else {
return CONN_OFFLINE;
}
}
public static boolean isOnline(Context context) {
int connState = ConnectivityState(context);
if(connState >= 0x10) {
return true;
}
else {
return false;
}
}
public static boolean isConnecting(Context context) {
int connState = ConnectivityState(context);
if(connState > 0x00 && connState < 0x10) {
return true;
}
else {
return false;
}
}
public static boolean isOffline(Context context) {
if(isOnline(context)) {
return false;
}
else {
return true;
}
}
public final static int CONN_OFFLINE = 0x00;
public final static int CONN_DIALING_MOBILE = 0x01;
public final static int CONN_DIALING_WIFI = 0x02;
public final static int CONN_DIALING_WIMAX = 0x03;
public final static int CONN_ONLINE_MOBILE = 0x11;
public final static int CONN_ONLINE_WIFI = 0x12;
public final static int CONN_ONLINE_WIMAX = 0x13;
} |
| | |
![]() |
|
| Themen-Optionen | |
| Ansicht | |
| |
| ||||
| Thema | Autor | Forum | Antworten | Letzter Beitrag |
| Netzwerkstatus ermitteln | burnersk | Android App Entwicklung | 1 | 03.06.2011 14:48 |
| displaygröße ermitteln | mr.freeze | Android App Entwicklung | 2 | 24.02.2011 09:03 |
| Handyposition ermitteln (rotation?!) | assenda | Android App Entwicklung | 1 | 23.12.2010 17:47 |
| Erstbetrieb ermitteln? | dream88 | HTC Desire HD Forum | 0 | 03.12.2010 17:21 |
| GeoStandort ermitteln | mr.freeze | Android App Entwicklung | 2 | 02.12.2010 08:38 |