Verbindungsprotokoll ermitteln

B

burnersk

Neues Mitglied
0
Hallo,

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;
    
}
API-Level: 8
 

Ähnliche Themen

E
Antworten
0
Aufrufe
699
enrem
E
J
  • JoEntwickler
Antworten
0
Aufrufe
974
JoEntwickler
J
J
Antworten
4
Aufrufe
807
deek
D
Zurück
Oben Unten