Google Android - how to figure out if 3g and 2g is turned on

后端 未结 2 732
小鲜肉
小鲜肉 2020-12-14 11:42

I\'m developing a simple application for the Google Android to turn on and off the wifi or 3g or 2g.

I see http://developer.android.com/reference/android/net/wifi/Wi

相关标签:
2条回答
  • 2020-12-14 12:46

    2G/3G

    To determine your network type use:

    TelephonyManager.getNetworkType();
    

    here's some example code:

    bool is3G = (manager.getNetworkType() == TelephonyManager.NETWORK_TYPE_UMTS);
    

    Docs for the class can be found at: TelephonyManager


    On/Off

    To check if your telephone radio is on or off use:

    ServiceState.getState();
    

    To set it use:

    ServiceState.setState(STATE_POWER_OFF);
    

    It's unclear whether the setState method exists on all devices and functions in all states. There is no documentation for this method. Documentation for the class can be found at: ServiceState

    This issue might also be relevant: http://code.google.com/p/android/issues/detail?id=1065

    0 讨论(0)
  • 2020-12-14 12:46

    You can also use ConnectivityManager. Something like that:

    ConnectivityManager connectivityManager =(ConnectivityManager)mContext.getSystemService(Context.CONNECTIVITY_SERVICE); 
    NetworkInfo activeNetInfo = connectivityManager.getActiveNetworkInfo();
    
    0 讨论(0)
提交回复
热议问题