Any one help me out to fetch wifi Signal strength ?
You can get the signal in levels by using:
WifiManager wifi = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
int levels = 5;
WifiInfo wifiInfo = wifi.getConnectionInfo();
int level = WifiManager.calculateSignalLevel(wifiInfo.getRssi(), numberOfLevels);
Refer to this answer for further help.
Related
I want to know is there any way to determine whatever I am logging should go through WIFI instead of device network,Is there any methods as part of Log entries SDK
Try this code for wifi connection or not.
private boolean checkConnectedToDesiredWifi() {
boolean connected = false;
WifiManager wifiManager =(WifiManager) context.getSystemService(Context.WIFI_SERVICE);
WifiInfo wifiInf = wifiManager.getConnectionInfo();
String desiredMacAddress = wifiInf.getMacAddress();
WifiInfo wifi = wifiManager.getConnectionInfo();
if (wifi != null) {
// get current router Mac address
String bssid = wifi.getBSSID();
connected = desiredMacAddress.equals(bssid);
}
return connected;
}
I am using below code to remove or forgot configure Wi-Fi network:
WifiManager wifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE);
wifiManager.removeNetwork(networkID);
but its not working in os 6.0, please suggest?
You should use like this:
WifiManager wifiManager = (WifiManager) getApplicationContext().getSystemService(Context.WIFI_SERVICE);
int networkId = wifiManager.getConnectionInfo().getNetworkId();
wifiManager.removeNetwork(networkId);
wifiManager.saveConfiguration();
Hope it will helps you !!
I'm trying to get the Wi-Fi signal strength of the AP connected. When I try to run the below code, nothing is returned/displays error.
public class Wifi extends uiscenario {
public void onReceive(WifiManager wifiManager) throws UiObjectNotFoundException, InterruptedException, RemoteException, IOException {
System.out.println("level");
int numberOfLevels=4;
WifiInfo wifiInfo = wifiManager.getConnectionInfo();
int level=WifiManager.calculateSignalLevel(wifiInfo.getRssi(), numberOfLevels);
System.out.println("Bars =" +level);
}
}
How to get the signal strength of the wifi connected and also how to get the scan results of wifi and connect to the wifi which has strongest signal strength?
Updated code
public class Wifi extends UiScenario {
private static WifiManager wifiManager;
public void wifiscan() throws UiObjectNotFoundException,InterruptedException,RemoteException, IOException {
int numberOfLevels=5;
WifiInfo wifiInfo = wifiManager.getConnectionInfo();
int level=WifiManager.calculateSignalLevel(wifiInfo.getRssi(), numberOfLevels);
System.out.println("Bars =" +level);
}
}
Getting error in this line(WifiInfo wifiInfo = wifiManager.getConnectionInfo();)
Hope it should work. Its working fine for me.
WifiManager wifiManager = (WifiManager)context.getSystemService(Context.WIFI_SERVICE);
int linkSpeed = wifiManager.getConnectionInfo().getRssi();
WifiManager wifiManager = (WifiManager)getSystemService(Context.WIFI_SERVICE);
int linkSpeed = wifiManager.getConnectionInfo().getRssi();
System.out.println("Link Speed is======"+linkSpeed);
Check your manifest uses permissions for wifi and read phone state your code is perfect,
it should work else try this.
WifiManager wifiManager = (WifiManager)context.getSystemService(Context.WIFI_SERVICE);
int linkSpeed = wifiManager.getConnectionInfo().getRssi();
I need to determine if the Android device is connected to Wifi, and if so, obtain its Wifi IP address.
I know how to use ConnectivityManager to determine whether the active network is a Wifi network, and I know how to use java.net.NetworkInterface to iterate over the available network interfaces and get their IP addresses.
What I don't know how to do is determine which IP address belongs to the Wifi network, if there is more than one address found. Any advice?
Thanks.
public String getIpAddr() {
WifiManager wifiManager = (WifiManager) getSystemService(WIFI_SERVICE);
WifiInfo wifiInfo = wifiManager.getConnectionInfo();
int ip = wifiInfo.getIpAddress();
String ipString = String.format(
"%d.%d.%d.%d",
(ip & 0xff),
(ip >> 8 & 0xff),
(ip >> 16 & 0xff),
(ip >> 24 & 0xff));
return ipString;
}
Please Note: You need to add android.permission.INTERNET and android.permission.ACCESS_WIFI_STATE in your AndroidManifest.xml as <user-permission/> to access the code.
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
Please try this code.
ConnectivityManager connec = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
//To fetch the state of the Wi-Fi network in the device
Boolean isWifi = connec.getNetworkInfo(ConnectivityManager.TYPE_WIFI).isConnectedOrConnecting();
WifiManager wifiMgr = (WifiManager) getBaseContext().getSystemService(Context.WIFI_SERVICE);
WifiInfo wifiInfo = wifiMgr.getConnectionInfo();
//To fetch the name of the Wi-Fi network to which the device is connected
String wifiName = wifiInfo.getSSID();
static final int IP_ADDRESS_LENGTH = 32;
public static Integer getSystemWifiIpAddress(Context context)
{
WifiManager wManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
WifiInfo wInfo = wManager.getConnectionInfo();
int ipAddress = wInfo.getIpAddress();
if (ipAddress == 0)
return null;
return ipAddress;
}
how to get macid and mobile number only in android mobile device not in database
try this
WifiManager manager = (WifiManager) getSystemService(Context.WIFI_SERVICE);
WifiInfo wifiInfo = manager.getConnectionInfo();
String MACAddress = wifiInfo.getMacAddress();