歡迎大家在這裡學習判斷android當前網絡連接狀態!下面是我們給大家整理出來的精彩內容。希望大家在這裡學習!
ConnectivityManager conMan = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo mobileNetworkInfo = conMan.getNetworkInfo(ConnectivityManager.TYPE_MOBILE); NetworkInfo wifiNetworkInfo = conMan.getNetworkInfo(ConnectivityManager.TYPE_WIFI); if(mobileNetworkInfo.isConnected()) { Log.v("網絡連接","當前為移動連接"); } if(wifiNetworkInfo.isConnected()) { Log.v("網絡連接","當前為WIFI連接"); } State mobileState = mobileNetworkInfo.getState(); State wifiState = wifiNetworkInfo.getState(); if(mobileState==State.CONNECTING) { }else if(mobileState==State.CONNECTED) { }
好了,判斷android當前網絡連接狀態內容就給大家介紹到這裡了。希望大家繼續關注我們的網站!
相關推薦:
android發送短信代碼介紹