Android app to check wifi status on or off.

15/04/2017   03:45:42 PM

Hello in this android article i will explain how to create android app to check wifi status of your android mobile on or off.WifiManager is the class which provides API for managing all things of Wi-Fi connectivity.we implement an instance of this class by calling Context.getSystemService(Context.WIFI_SERVICE)

1.Create new project in android studio/add following code to app/res/layout/activity_main.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
    android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity">
</RelativeLayout>
 
2. Add following code on MainActivity.Java
 
 
import android.content.Context;
import android.net.wifi.WifiManager;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.Toast;
import android.widget.ToggleButton;

 
public class MainActivity extends ActionBarActivity   {
   private WifiManager  wfm;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        //get the wifi service of device
    wfm= (WifiManager) this.getSystemService(Context.WIFI_SERVICE);
        //check wifi currently on or off
       if(wfm.isWifiEnabled()) {
            Toast.makeText(this, "Wifi Enabled", Toast.LENGTH_SHORT).show();
        }
        else
        {
            Toast.makeText(this,"Wifi disabled",Toast.LENGTH_SHORT).show();
        }
   }

 

3. Add following code in AndroidManifest.xml file above <application> element

<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>

 OUTPUT

android app to check wifi status on or off


Output

                   

Support us by Sharing