get Wifi Strength - Android Phone

Android examples for Phone:wifi

Description

get Wifi Strength

Demo Code


//package com.java2s;

import android.net.wifi.ScanResult;

import android.net.wifi.WifiManager;

public class Main {
    /**/*w w w .  j  a  v  a2s  .co m*/
     *
     * @param result
     * @return Normalize DB level to percentage
     */
    public static int getWifiStrength(ScanResult result) {
        try {
            int level = WifiManager.calculateSignalLevel(result.level, 10);
            int percentage = (int) ((level / 10.0) * 100);
            return percentage;
        } catch (Exception e) {
            return 0;
        }
    }
}

Related Tutorials