Skip to main content

Show the updated Wi-Fi and Bluetooth status in Android

Hi, Everyone Wish you happy new year 2017. Here we going to see about the show the updated Wi-Fi and Bluetooth status using broadcast receiver.

Add the permissions below in AndroidManifest.xml
    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.BLUETOOTH" />

In your Activity, Add this,

/* Wifi Status*/
    private BroadcastReceiver myWifiReceiver
            = new BroadcastReceiver() {

        public void onReceive(Context arg0, Intent arg1) {
            // TODO Auto-generated method stub
            NetworkInfo networkInfo = (NetworkInfo) arg1.getParcelableExtra(ConnectivityManager.EXTRA_NETWORK_INFO);
            if (networkInfo.getType() == ConnectivityManager.TYPE_WIFI) {

/*Bluetooth Status*/
private final BroadcastReceiver bluetoothReceiver = new BroadcastReceiver() {
        public void onReceive(Context context, Intent intent) {
            final String action = intent.getAction();

            if (action.equals(BluetoothAdapter.ACTION_STATE_CHANGED)) {
                final int state = intent.getIntExtra(BluetoothAdapter.EXTRA_STATE,
                switch (state) {
                    case BluetoothAdapter.STATE_OFF:
                        txt_bluetooth.setText("Bluetooth off");
                    case BluetoothAdapter.STATE_TURNING_OFF:
                        txt_bluetooth.setText("Turning Bluetooth off...");
                    case BluetoothAdapter.STATE_ON:
                        txt_bluetooth.setText("Bluetooth on");
                    case BluetoothAdapter.STATE_TURNING_ON:
                        txt_bluetooth.setText("Turning Bluetooth on...");
            } else {
                txt_bluetooth.setText("Bluetooth off");

/*Method for Display wifi status*/
private void DisplayWifiState() {

        ConnectivityManager myConnManager = (ConnectivityManager) getSystemService(CONNECTIVITY_SERVICE);
        NetworkInfo myNetworkInfo = myConnManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
        WifiManager myWifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE);
        WifiInfo myWifiInfo = myWifiManager.getConnectionInfo();
        String macAddress, IPaddress, ssId, BssId, speed, rssi, connected;

        macAddress = myWifiInfo.getMacAddress();

        if (myNetworkInfo.isConnected()) {
            int myIp = myWifiInfo.getIpAddress();
            connected = " CONNECTED ";

            int intMyIp3 = myIp / 0x1000000;
            int intMyIp3mod = myIp % 0x1000000;

            int intMyIp2 = intMyIp3mod / 0x10000;
            int intMyIp2mod = intMyIp3mod % 0x10000;

            int intMyIp1 = intMyIp2mod / 0x100;
            int intMyIp0 = intMyIp2mod % 0x100;

            IPaddress = String.valueOf(intMyIp0)
                    + "." + String.valueOf(intMyIp1)
                    + "." + String.valueOf(intMyIp2)
                    + "." + String.valueOf(intMyIp3);

            ssId = myWifiInfo.getSSID();
            BssId = myWifiInfo.getBSSID();

            speed = String.valueOf(myWifiInfo.getLinkSpeed()) + " " + WifiInfo.LINK_SPEED_UNITS;
            rssi = String.valueOf(myWifiInfo.getRssi());
            txt_wifi.setText(connected + "\n" + " Mac Address : " + macAddress + "\n" + " IP Address : " + IPaddress + "\n"
                    + " SSID : " + ssId + "\n" + " BSSID : " + BssId + "\n" + " Speed : " + speed + "\n" + " RSSI : " + rssi);
        } else {
            connected = " DIS-CONNECTED! ";


In your OnCreate(), just add this,
//For Wifi
                new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION));

//For Bluetooth
this.registerReceiver(bluetoothReceiver,  new IntentFilter(BluetoothAdapter.ACTION_STATE_CHANGED));

To Unregister the status:
public void onDestroy() {

Need Code, Just Visit my Github


Popular posts from this blog

Clear the app data programmatically in android

Clear the App Data Programmatically in Android

Application data has been created due to use shared preference data, databases and network caches data. This data has been manually clear on Settings -- > Apps (or) Application Manager --> Select the app you want to clear the data. --> Then click button clear data to erase the app from the Phone and SDCARD.

Applications like facebook, google+, gmail and some games captures more data on phone and SDCARD.

Once you clear the data of your app, all passwords and saved settings in app has been lost. So carefull to use this method.

Create the Class MyApplication

public class MyApplication extends Application {
 private static MyApplication instance;
 public void onCreate() {
  instance = this;
 public static MyApplication getInstance(){
  return instance;
 public void clearApplicationData() {
  File cache = getCacheDir();
  File appDir = new File(cache.getParent());
   String[] children = app…

convert an integer to a string in java

Hi, have a great day. Hope It's like to be homework question or to be interview question. Yes, it's right. In future posts, I'm gonna be post a interview questions and answers, algorithms and some critical problems.

1) return an empty string if value is negative.
2) return an empty string if the conversion fails.
3) return the proper string of the value using characer '0' to '9' and 'A' to 'F'
for example:
MyIntToString(254, 16) return "FE"
MyIntToString(254,  8) return "376"
MyIntToString(254,  2) return "11111110"

1) You SHALL NOT import any Java libraries for the implementation.
2) You are allowed to using the string class related functions, like: insert(),
appened, trim()and etc for the implementation
3) You SHALL NOT invoke static functions from java.lang.Integer class to perform the conversion.
4) Your code style is graded, hence it is encouraged to structure the code professionally
and equip…

Print the large string values in android log cat.


Have a happy Monday.

In Android, sometimes we need to print the large numbers of strings value in log. But log can't accept whole value of the string.

In this case, we need to split the logs. It's very simple android code, I attached below this blog.

public static void logLargeString(String TAG, String msg) {         if (str.length() > 3000) {             Log.i(TAG, msg.substring(0, 3000));             logLargeString(TAG, msg.substring(3000));         } else {             Log.i(TAG, msg);         } }
Just use it and enjoy...