Sunday 31 May 2015

SDcard information or check current status

No comments
          Hello friends, in this android example i show you how to get storage information of SDcard, And check status of SDcard like its mounted or available in devise or not.here is simple code is to get Total size of SDcard and Remaining space.Lets go for coding.In this we get size of storage in GB,MB,KB and Byte.


CREATE NEW ANDROID PROJECT


Step 1: Write code into activity_main.xml


<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <TextView
        android:id="@+id/state"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="15dip"
        android:textStyle="bold"
        android:typeface="normal" >
    </TextView>

    <TextView
        android:id="@+id/info"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="4dip" >
    </TextView>

</LinearLayout>


Step 2:Write code into MainActivity.java


package dev.Androidapplink.sdcardinfoapp;

import java.text.NumberFormat;

import dev.Androidapplink.sdcardinfoapp.R;

import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import android.os.Environment;
import android.os.StatFs;
import android.widget.TextView;

public class MainActivity extends Activity 
{
//the statistics of the SD card
private StatFs stats;
//the state of the external storage
private String externalStorageState;

//the total size of the SD card
private double totalSize;
//the available free space
private double freeSpace;

//a String to store the SD card information
private String outputInfo;
//a TextView to output the SD card state
private TextView tv_state;
//a TextView to output the SD card information
private TextView tv_info;

//set the number format output
private NumberFormat numberFormat;

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) 
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        
        //initialize the Text Views with the data at the main.xml file
        tv_state = (TextView)findViewById(R.id.state);
        tv_info = (TextView)findViewById(R.id.info);
        
        //get external storage (SD card) state
        externalStorageState = Environment.getExternalStorageState();
        
        //checks if the SD card is available in device 
        if(externalStorageState.equals(Environment.MEDIA_MOUNTED)
        || externalStorageState.equals(Environment.MEDIA_UNMOUNTED)
        || externalStorageState.equals(Environment.MEDIA_MOUNTED_READ_ONLY))
        {
        //obtain the stats from the root of the SD card.
        stats = new StatFs(Environment.getExternalStorageDirectory().getPath());
       
        //Add 'Total Size' to the output string:
        outputInfo = "\nTotal Size:\n";
       
        //total usable size
        totalSize = stats.getBlockCount() * stats.getBlockSize();
       
        //initialize the NumberFormat object
        numberFormat = NumberFormat.getInstance();
        //disable grouping
        numberFormat.setGroupingUsed(false);
        //display numbers with two decimal places
        numberFormat.setMaximumFractionDigits(2); 
       
        //SD card's total size in gigabytes, megabytes, kilobytes and bytes
        outputInfo += "Size in gigabytes: " + numberFormat.format((totalSize / (double)1073741824)) + " GB \n"
        + "Size in megabytes: " + numberFormat.format((totalSize / (double)1048576)) + " MB \n" 
        + "Size in kilobytes: " + numberFormat.format((totalSize / (double)1024)) + " KB \n" 
        + "Size in bytes: " +  numberFormat.format(totalSize) + " B \n"; 
       
        //Add 'Remaining Space' to the output string:
        outputInfo += "\nRemaining Space:\n";
       
        //available free space
        freeSpace = stats.getAvailableBlocks() * stats.getBlockSize();
       
        //SD card's available free space in gigabytes, megabytes, kilobytes and bytes
        outputInfo += "Size in gigabytes: " + numberFormat.format((freeSpace / (double)1073741824)) + " GB \n"
        + "Size in megabytes: " + numberFormat.format((freeSpace / (double)1048576)) + " MB \n" 
        + "Size in kilobytes: " + numberFormat.format((freeSpace / (double)1024)) + " KB \n"
        + "Size in bytes: " + numberFormat.format(freeSpace) + " B \n"; 
       
        //output the SD card state
        tv_state.setTextColor(Color.GREEN);
        tv_state.setText("SD card found! SD card is " + externalStorageState +".");
       
        //output the SD card info
        tv_info.setText(outputInfo);
        }
        else //external storage was not found
        {
        //output the SD card state
        tv_state.setTextColor(Color.RED);
        tv_state.setText("SD card not found! SD card state is \"" + externalStorageState + "\".");
        }
    }
}

NOTE:Give permission in AndroidManifest.xml

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


Step 3:Run project to see Output:





Transparent color code in android

4 comments
        

      Hello friends,In this tutorial i show you how to set color as a transparent by using HEX code e.g.FFFFFF (solid White). transparent means like a glass.we can see view object which is  behind of first object,in android we can see Layout which is  behind of first Layout.

          In this example i give you color code that help you to make any color as a Transparent color. basically Black and white is widely use to set transparent color background of any object such as Button,Label,Layout color etc.

          Mostly solid color is use to set color that we can write like this "#FFF" (RGB) or "#FFFFFF" (RRGGBB) White color,but now we want to convert this solid white color into Transparent color than we write like this "#30FFFFFF", it meant we set color opacity (transparency-level) 30% transparent.

  • "FF" = 100% solid
  • "00" = 0% (Black)

Here i provide you some transparent color code with a percentage wise in a string format:




<!--Transparent Black HEX-->



<color name="transparent_black_1">#11000000</color>
<color name="transparent_black_2">#22000000</color>
<color name="transparent_black_3">#33000000</color>
<color name="transparent_black_4">#44000000</color>
<color name="transparent_black_5">#55000000</color>
<color name="transparent_black_6">#66000000</color>
<color name="transparent_black_7">#77000000</color>
<color name="transparent_black_8">#88000000</color>
<color name="transparent_black_9">#99000000</color>
<color name="transparent_black_10">#aa000000</color>
<color name="transparent_black_11">#bb000000</color>
<color name="transparent_black_12">#cc000000</color>
<color name="transparent_black_13">#dd000000</color>
<color name="transparent_black_14">#ee000000</color>
<color name="transparent_black_15">#ff000000</color>
<color name="transparent_black_16">#80000000</color>
<color name="transparent_white_17">#A0000000</color>

Take Ratio 5%:

<color name="transparent_black_5">#0D000000</color>
<color name="transparent_black_10">#1A000000</color>
<color name="transparent_black_15">#26000000</color>
<color name="transparent_black_20">#33000000</color>
<color name="transparent_black_25">#40000000</color>
<color name="transparent_black_30">#4D000000</color>
<color name="transparent_black_35">#59000000</color>
<color name="transparent_black_40">#66000000</color>
<color name="transparent_black_45">#73000000</color>
<color name="transparent_black_50">#80000000</color>
<color name="transparent_black_55">#8C000000</color>
<color name="transparent_black_60">#99000000</color>
<color name="transparent_black_65">#A6000000</color>
<color name="transparent_black_70">#B3000000</color>
<color name="transparent_black_75">#BF000000</color>
<color name="transparent_black_80">#CC000000</color>
<color name="transparent_black_85">#D9000000</color>
<color name="transparent_black_90">#E6000000</color>
<color name="transparent_black_95">#F2000000</color>

<!--Transparent White HEX-->

<color name="transparent_white_1">#11ffffff</color>
<color name="transparent_white_2">#22ffffff</color>
<color name="transparent_white_3">#33ffffff</color>
<color name="transparent_white_4">#44ffffff</color>
<color name="transparent_white_5">#55ffffff</color>
<color name="transparent_white_6">#66ffffff</color>
<color name="transparent_white_7">#77ffffff</color>
<color name="transparent_white_8">#88ffffff</color>
<color name="transparent_white_9">#99ffffff</color>
<color name="transparent_white_10">#aaffffff</color>
<color name="transparent_white_11">#bbffffff</color>
<color name="transparent_white_12">#ccffffff</color>
<color name="transparent_white_13">#ddffffff</color>
<color name="transparent_white_14">#eeffffff</color>
<color name="transparent_white_15">#ffffffff</color>
<color name="transparent_white_16">#80ffffff</color>
<color name="transparent_white_17">#A0ffffff</color>

Take Ratio 5%:

<color name="transparent_white_5">#0Dffffff</color>
<color name="transparent_white_10">#1Affffff</color>
<color name="transparent_white_15">#26ffffff</color>
<color name="transparent_white_20">#33ffffff</color>
<color name="transparent_white_25">#40ffffff</color>
<color name="transparent_white_30">#4Dffffff</color>
<color name="transparent_white_35">#59ffffff</color>
<color name="transparent_white_40">#66ffffff</color>
<color name="transparent_white_45">#73ffffff</color>
<color name="transparent_white_50">#80ffffff</color>
<color name="transparent_white_55">#8Cffffff</color>
<color name="transparent_white_60">#99ffffff</color>
<color name="transparent_white_65">#A6ffffff</color>
<color name="transparent_white_70">#B3ffffff</color>
<color name="transparent_white_75">#BFffffff</color>
<color name="transparent_white_80">#CCffffff</color>
<color name="transparent_white_85">#D9ffffff</color>
<color name="transparent_white_90">#E6ffffff</color>
<color name="transparent_white_95">#F2ffffff</color>

Now i show you how to make any color as a transparent color in percentage(%).

  • 100% — FF
  • 99% — FC
  • 98% — FA
  • 97% — F7
  • 96% — F5
  • 95% — F2
  • 94% — F0
  • 93% — ED
  • 92% — EB
  • 91% — E8

  • 90% — E6
  • 89% — E3
  • 88% — E0
  • 87% — DE
  • 86% — DB
  • 85% — D9
  • 84% — D6
  • 83% — D4
  • 82% — D1
  • 81% — CF

  • 80% — CC
  • 79% — C9
  • 78% — C7
  • 77% — C4
  • 76% — C2
  • 75% — BF
  • 74% — BD
  • 73% — BA
  • 72% — B8
  • 71% — B5

  • 70% — B3
  • 69% — B0
  • 68% — AD
  • 67% — AB
  • 66% — A8
  • 65% — A6
  • 64% — A3
  • 63% — A1
  • 62% — 9E
  • 61% — 9C

  • 60% — 99
  • 59% — 96
  • 58% — 94
  • 57% — 91
  • 56% — 8F
  • 55% — 8C
  • 54% — 8A
  • 53% — 87
  • 52% — 85
  • 51% — 82

  • 50% — 80
  • 49% — 7D
  • 48% — 7A
  • 47% — 78
  • 46% — 75
  • 45% — 73
  • 44% — 70
  • 43% — 6E
  • 42% — 6B
  • 41% — 69

  • 40% — 66
  • 39% — 63
  • 38% — 61
  • 37% — 5E
  • 36% — 5C
  • 35% — 59
  • 34% — 57
  • 33% — 54
  • 32% — 52
  • 31% — 4F

  • 30% — 4D
  • 29% — 4A
  • 28% — 47
  • 27% — 45
  • 26% — 42
  • 25% — 40
  • 24% — 3D
  • 23% — 3B
  • 22% — 38
  • 21% — 36

  • 20% — 33
  • 19% — 30
  • 18% — 2E
  • 17% — 2B
  • 16% — 29
  • 15% — 26
  • 14% — 24
  • 13% — 21
  • 12% — 1F
  • 11% — 1C

  • 10% — 1A
  • 9% — 17
  • 8% — 14
  • 7% — 12
  • 6% — 0F
  • 5% — 0D
  • 4% — 0A
  • 3% — 08
  • 2% — 05
  • 1% — 03
  • 0% — 00 


          To make any transparent color by using above value which is show transparent level of color. let we take a example to convert solid white color convert in 40% transparent,

  • Solid white color "#FFFFFF" to Transparent color "#66FFFFFF"
  • Solid Black color "#000000" to Transparent color "#80000000"




I hope this tutorial may helpful for you.


Android activity example | Button click event

No comments
In this tutorial, we show you how to interact with activity by implement On button click activity. when a button is clicked, go one screen to another screen.Open one XML file to another XML file on button click.Most applications have multiple activities to represent different screens, for e.g. one activity to display a list of the application status and another activity is to display the application functions,settings etc...

CREATE NEW ANDROID PROJECT

In this example we need Two XML file and Two java file.
XML:
1) activity_main.xml
2) activity_main2.xml


JAVA:
1) MainActivity.java
2) MainActivity2.java

Step 1: Write code into activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/linearLayout1"

android:layout_width="fill_parent"

android:layout_height="fill_parent"
android:orientation="vertical" >



    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="First screen (activity_main.xml)"
        android:textAppearance="?android:attr/textAppearanceLarge" />

    <Button
        android:id="@+id/button1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="Click me" />

</LinearLayout>

Step 2: Write code into activity_main2.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/linearLayout1"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Second screen (activity_main2.xml)"
        android:textAppearance="?android:attr/textAppearanceLarge" />

</LinearLayout>

Step 3: Write code into MainActivity.java

package com.example.activityapp;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.widget.Button;
import android.view.View;
import android.view.View.OnClickListener;

public class MainActivity extends Activity {

Button button;

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
addListenerOnButton();
}

public void addListenerOnButton() {

final Context context = this;

button = (Button) findViewById(R.id.button1);

button.setOnClickListener(new OnClickListener() {

@Override
public void onClick(View arg0) {

Intent intent = new Intent(context, MainActivity2.class);
                startActivity(intent);   

}

});

}

}


Step 4: Write code into MainActivity2.java

package com.example.activityapp;

import android.app.Activity;
import android.os.Bundle;
import android.widget.Button;

public class MainActivity2 extends Activity {

Button button;

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main2);
}

}

Step 5: write code into AndroidManifest.xml

Register second activity in Androidmanifest.xml file.

        <activity
            android:name=".MainActivity2"
            android:label="@string/app_name" >
        </activity>

IT's look like this:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.activityapp"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="18" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="com.example.activityapp.MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:name=".MainActivity2"
            android:label="@string/app_name" >
        </activity>
    </application>

</manifest>

Step 6:Now Run Your Project:




Adjust screen brightness in android

1 comment
In this tutorial i show you,how to adjust screen brightness programatically in android.In this example we learn get current screen brightness state and changing screen brightness.

CREATE NEW ANDROID PROJECT

Step 1: Write code into activity_main.xml

<LinearLayout 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:orientation="vertical"
    tools:context=".MainActivity" >

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:layout_margin="10dp"
        android:text="Slide seekbar to change the brightness" />

    <TextView
        android:id="@+id/txtPercentage"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:layout_margin="10dp"
        android:text="0%"
        android:textAppearance="?android:attr/textAppearanceLarge" />

    <SeekBar
        android:id="@+id/brightbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="5dp"
        android:layout_marginRight="5dp" />


</LinearLayout>

Step 2: Write code into MainActivity.java

package dev.Androidapplink.setscreenbrightnessapp;

import dev.Androidapplink.setscreenbrightnessapp.R;

import android.app.Activity;
import android.content.ContentResolver;
import android.os.Bundle;
import android.provider.Settings.System;
import android.util.Log;
import android.view.Window;
import android.view.WindowManager.LayoutParams;
import android.widget.SeekBar;
import android.widget.SeekBar.OnSeekBarChangeListener;
import android.widget.TextView;

public class MainActivity extends Activity {


//Seek bar object
private SeekBar brightbar;

//Variable to store brightness value
private int brightness;

//handle to the system's settings
private ContentResolver cResolver;

//Window object store a reference to the current window
private Window window;

TextView txtPerc;
   

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

        //Instantiate seekbar object
brightbar = (SeekBar) findViewById(R.id.brightbar);

txtPerc = (TextView) findViewById(R.id.txtPercentage);

        //Get the content resolver
cResolver = getContentResolver();

        //Get the current window
window = getWindow();

        //Set the seekbar range between 0 and 255
brightbar.setMax(255);

        //Set the seek bar progress to 1
brightbar.setKeyProgressIncrement(1);

try {
        //Get the current system brightness state
brightness = System.getInt(cResolver, System.SCREEN_BRIGHTNESS);
float perc = (brightness /(float)255)*100;
txtPerc.setText((int)perc + "%");
} catch (Exception e) {
// TODO: handle exception
        //Throw an error case it couldn't be retrieved
Log.e("Error", "cannot access system brightness.");
e.printStackTrace();
}

//Set the progress of the seek bar based on the system's brightness
brightbar.setProgress(brightness);


//Register OnSeekBarChangeListener, so it can actually change values
brightbar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {

@Override
public void onStopTrackingTouch(SeekBar seekBar) {
// TODO Auto-generated method stub

//Set the system brightness using the brightness variable value
System.putInt(cResolver, System.SCREEN_BRIGHTNESS, brightness);
//Get the current window attributes
LayoutParams layoutpars = window.getAttributes();

//Set the brightness of this window
layoutpars.screenBrightness = brightness / (float)255;
//Apply attribute changes to this window
window.setAttributes(layoutpars);

}

@Override
public void onStartTrackingTouch(SeekBar seekBar) {
// TODO Auto-generated method stub

//Nothing handled here
}

@Override
public void onProgressChanged(SeekBar seekBar, int progress,
boolean fromUser) {
// TODO Auto-generated method stub
//Set the minimal brightness level
if(progress<=20)
{

brightness=20;
}
else //brightness is greater than 20
{
//Set brightness variable based on the progress bar 
brightness = progress;
}

//Calculate the brightness percentage
float perc = (brightness /(float)255)*100;

//Set the brightness percentage 
txtPerc.setText((int)perc + "%");

}
});
}
//IT WORK ONLY,IF SCREEN BRIGHTNESS IS NOT SETED IN "AUTO BRIGHTNESS MODE".

}

NOTE: Give permission in AndroidManifest.xml
It allow to change setting.

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

Step 3: Run project and see Output:





Turn Wifi On/Off using WifiManager and get current state

1 comment
In this tutorial we learn hoe to write code for turn on/off wifi using WifiManager in android example.Here not only turn on/off wifi,but get current state of wifi and change image according to state.

CREATE NEW ANDROID PROJECT

Step 1: Write code into 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:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".MainActivity" >

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:text="@string/hello_world" />

    <ImageButton
        android:id="@+id/onwifi"
        android:layout_width="130dp"
        android:layout_height="130dp"
        android:layout_alignParentLeft="true"
        android:layout_centerVertical="true"
        android:contentDescription="@null"
        android:src="@drawable/wifproc" />

    <ImageButton
        android:id="@+id/offwifi"
        android:layout_width="130dp"
        android:layout_height="130dp"
        android:layout_alignTop="@+id/onwifi"
        android:layout_marginLeft="18dp"
        android:layout_toRightOf="@+id/onwifi"
        android:contentDescription="@null"
        android:src="@drawable/wifiisoff" />


</RelativeLayout>

Step 2: Write code into MainActivity.java

package dev.androidapplink.wifiapp;

import android.app.Activity;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.net.wifi.WifiManager;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageButton;

public class MainActivity extends Activity {

ImageButton OnWifi;
ImageButton OffWifi;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

// wifi on off control
OnWifi = (ImageButton) findViewById(R.id.onwifi);
OffWifi = (ImageButton) findViewById(R.id.offwifi);

// call state change receiver
this.registerReceiver(this.WifiStateChangedReceiver, new IntentFilter(
WifiManager.WIFI_STATE_CHANGED_ACTION));
// set button click event
OnWifi.setOnClickListener(new Button.OnClickListener() {

@Override
public void onClick(View arg0) {

// TODO Auto-generated method stub
// get wifi service

WifiManager wifiManager = (WifiManager) getBaseContext()
.getSystemService(Context.WIFI_SERVICE);
wifiManager.setWifiEnabled(true);
}
});
// set button click event
OffWifi.setOnClickListener(new Button.OnClickListener() {

@Override
public void onClick(View arg0) {

// TODO Auto-generated method stub
// get wifi service
WifiManager wifiManager = (WifiManager) getBaseContext()
.getSystemService(Context.WIFI_SERVICE);
wifiManager.setWifiEnabled(false);
}
});

}
// call state change receiver on button click
//set image according to wifi state
private BroadcastReceiver WifiStateChangedReceiver = new BroadcastReceiver() {

@Override
public void onReceive(Context context, Intent intent) {
// TODO Auto-generated method stub

int extraWifiState = intent.getIntExtra(
WifiManager.EXTRA_WIFI_STATE,
WifiManager.WIFI_STATE_UNKNOWN);

switch (extraWifiState) {
case WifiManager.WIFI_STATE_DISABLED:

OnWifi.setImageResource(R.drawable.wifioff);
OffWifi.setImageResource(R.drawable.wifiison);
break;
case WifiManager.WIFI_STATE_DISABLING:

OffWifi.setImageResource(R.drawable.wifproc);
break;
case WifiManager.WIFI_STATE_ENABLED:

OnWifi.setImageResource(R.drawable.wifion);
OffWifi.setImageResource(R.drawable.wifiisoff);

break;
case WifiManager.WIFI_STATE_ENABLING:

OnWifi.setImageResource(R.drawable.wifproc);
break;
case WifiManager.WIFI_STATE_UNKNOWN:

break;
}

}
};


}

NOTE:Give permission in AndroidManifest.xml
Its allow to change wifi network state according to setting.

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

Step 3: Now Run Your Project:










Follow me Share