Check WiFi and GPS isConnected or Not in Android?

前端 未结 4 1167
没有蜡笔的小新
没有蜡笔的小新 2020-12-03 02:17

I would need to check the wifi is on or off in the phone at the runtime?

if it is not connected, i want to show dialog and goto directly Setting/Wireless Controls to

4条回答
  •  广开言路
    2020-12-03 02:51

    ConnectivityManager conMan = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
    
    //mobile
    State mobile = conMan.getNetworkInfo(ConnectivityManager.TYPE_MOBILE).getState();
    
    //wifi
    State wifi = conMan.getNetworkInfo(ConnectivityManager.TYPE_WIFI).getState();
    

提交回复
热议问题