This article describes how to get the status of your Android device WiFi connection!
Add access permissions (in the Androidmanifest.xml file)
<uses-permission android:name= "Android.permission.ACCESS_NETWORK_STATE"/>
Java code (mainactivity.java file)
Package Com.example.androidtest;import Android.net.connectivitymanager;import android.net.NetworkInfo.State; Import Android.os.bundle;import android.app.activity;import Android.content.context;import Android.util.Log;import Android.view.menu;public class Mainactivity extends Activity {@Overrideprotected void OnCreate (Bundle Savedinstancestate) {super.oncreate (savedinstancestate); Setcontentview (R.layout.activity_main); Boolean bFlag = Iswifiavailable (This.getapplicationcontext ()); if (bflag) {log.i ("Wifi state-", "Connected");} else {log.i ("Wifi state-", "Not Connected");}} /** * Determine WiFi connection Status * * @param CTX * @return */public boolean iswifiavailable (Context ctx) {Connectivitymanager conman = (Co Nnectivitymanager) Ctx.getsystemservice (Context.connectivity_service); state WiFi = Conman.getnetworkinfo (Connectivitymanager.type_wifi). GetState (); if (state.connected = = WiFi) {return true ;} else {return false;}} @Overridepublic boolean Oncreateoptionsmenu (Menu menu) {//Inflate the menu; this adds Items to the Action bar if it is present.getmenuinflater (). Inflate (R.menu.activity_main, menu); return true;}}
Get the Android device WiFi connection status