android-wifi

Android Wifi Scan - BroadcastReceiver for SCAN_RESULTS_AVAILABLE_ACTION not getting called

萝らか妹 提交于 2019-11-29 15:20:59
问题 Here is my code: public class FloatWifiManager implements IWifiManager { private WifiManager wifiManager; private BroadcastReceiver wifiScanReceiver; public FloatWifiManager(Context context) { ... wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); // Registering Wifi Receiver wifiScanReceiver = new BroadcastReceiver() { @Override public void onReceive(Context c, Intent intent) { if (intent.getAction().equals(WifiManager.SCAN_RESULTS_AVAILABLE_ACTION)) { // not getting

How to get MAC address of the WIFI interface in android?

China☆狼群 提交于 2019-11-29 14:42:26
问题 I am using the following code: WifiManager wifiMgr = (WifiManager) app.getSystemService(Context.WIFI_SERVICE); return wifiMgr.getConnectionInfo().getMacAddress(); Problem is, the WIFI must be ENABLED in the device in order for me to read its address. How can I still read the MAC of the WIFI even if the WIFI is off? 回答1: You can't. Depending on the device, if the wifi adapter is disabled then it may actually be electronically switched off, so you can't read any info from it. From the Android

Android - Why ConnectivityManager.isActiveNetworkMetered always returning true (even when on Wifi)

江枫思渺然 提交于 2019-11-29 14:41:01
问题 In my music streaming app for Android, the code path below helps decides between a high bitrate stream vs. a lower bitrate based on values returned by the ConnectivityManager class instance. I am trying to understand why ConnectivityManager.isActiveNetworkMetered() would return "true", when it's evident I'm on a local Wifi network. Take the following Android/Java code: boolean isMetered = false; boolean isWifi = false; boolean isEthernet = false; boolean isRoaming = false; boolean isConnected

WifiManager.getScanResults() - clarifications (automatic scans, sleep etc)

两盒软妹~` 提交于 2019-11-29 12:45:28
I would like some clarifications on the behavior of WifiManager.getScanResults() , namely : When wireless is enabled Does android scan for access points on a fixed interval ? Can one query/change the interval ? Can one query the time of the last scan ? For a discussion see this answer What happens when the wireless radio is turned off (sleeps) - while wifi is still enabled - will getScanResults() go on returning the last scan results ? How would one know if it's time for startScan() ? When wireless is disabled getScanResults() would return the last scan results ? Or an empty List ? Or null (it

How To Resolve Network Host Names From IP Address

家住魔仙堡 提交于 2019-11-29 12:26:53
I am working on wifi based chat engine and I was able to retrieve the list of hosts connected to current wifi network by followin this link and now got list of devices with ip addresses but i need host name from the ip address and tried following InetAddress inetAddr; try { inetAddr = InetAddress.getByName(host.hostname); String hostname = inetAddr.getHostName(); String canonicalHostname = inetAddr.getCanonicalHostName(); holder.computerName.setText("Canonical : "+host.hostname); } catch (Exception e) { e.printStackTrace(); } Here the host name and canonical host name both are displaying ip

How to get BSSID of all wifi access points?

为君一笑 提交于 2019-11-29 12:06:59
问题 I need to get BSSID(MAC) of all AP's. Please find below code block. List<WifiConfiguration> test = wifiManager.getConfiguredNetworks(); for(int k=0;k<test.size();k++){ Log.d("acheck", "test BSSID = "+test.get(k).BSSID); Log.d("acheck", "test BSSID = "+test.get(k).BSSID); } But above code block returns SSID properly but null for BSSID. I want to connect to strongest access point with user defined SSID. Is there any API method available to get best signal strength's AP with user defined SSID.

How to force the HTTP connection over Wi-Fi instead of cellular in Android?

青春壹個敷衍的年華 提交于 2019-11-29 11:38:07
My application has to detect that the device connected to the Wi-Fi network is the required one and then fire a HTTP request over that Wi-Fi network programmatically. I have searched, but I didn't find any method or class which will help me to do this. I thought of disabling the cellular network so that the HTTP request will go through the Wi-Fi network but even in this I didn't have success. And also, can I enable and disable the cellular and Wi-Fi networks programatically? Robby Pond There is no way to force it to use one or the other. Whatever network is available is used whether 3G or Wi

Getting the MAC address of the device- when wifi is off

微笑、不失礼 提交于 2019-11-29 09:33:30
问题 I am finding the MAC address of the Android Device using the following code: WifiManager manager = (WifiManager) getSystemService(Context.WIFI_SERVICE); WifiInfo info = manager.getConnectionInfo(); String address = info.getMacAddress()); But in this case I am unable to get the MAC address when the Wifi is off. How can I get the MAC address of the Android Device even when WIFI is off. Thanks 回答1: Why not enable the Wifi momentarily until you get the MAC address and then disable it once you are

UDP broadcast packets not received in sleep mode

和自甴很熟 提交于 2019-11-29 08:48:31
My Android application periodically sends and receives UDP broadcast messages on the WiFi LAN. When the display is on, everything works fine and all messages are sent and received correctly. When the display goes to sleep the application however stops receiving UDP broadcast messages (but still sends them). Acquiring the WiFiLock (as well as a Multicast Lock) does not seem to make any difference and my wifi sleep policy is set to WIFI_SLEEP_POLICY_NEVER. This is an issue on Android 2.3.3 and 2.3.5 (Samsung galaxy SII phones) but not an issue on an old HTC Hero running cyanogen mod with android

How to get wifi hotspot state

醉酒当歌 提交于 2019-11-29 07:31:35
I am creating wifi hotspot in my phone and I want get its state change event when I switched on or off hotspot. Atul Panda Please look at the following code. This will help you public class WifiApManager { private final WifiManager mWifiManager; public WifiApManager(Context context) { mWifiManager = (WifiManager)context.getSystemService(Context.WIFI_SERVICE); } /*the following method is for getting the wifi hotspot state*/ public WIFI_AP_STATE getWifiApState() { try { Method method = mWifiManager.getClass().getMethod("getWifiApState"); int tmp = ((Integer) method.invoke(mWifiManager)); // Fix