The following will not turn wifi on, if the user has it turned off, right?:
WifiManager manager = (WifiManager)context.getSystemService(
Context.WIFI_SERVICE);
manager.startScan(); <-- !
I want to make sure the wifi isn't being turned on (if off) when the above is called,
Thanks
Yes, you are correct. The above code will not turn on wifi.
You can however use setWifiEnabled(true) to enable wi-fi access. You will need to add android.permission.CHANGE_WIFI_STATE to your manifest file.
Related
The Android Virtual Device is connected by defualt to a wifi network called "AndroidWifi". I am working with an app that expects to be connected to a wifi network with a particular name.
How can I change the name of the wifi network from "AndroidWifi"?
Try something more pragmatic:
String getExpectedId() {
String ssid = this.getResources().getString(R.string.default_ssid);
if(Build.FINGERPRINT.contains("generic")) {ssid = "AndroidWifi";}
return ssid;
}
because you won't change the SSID (service set identifier) of the emulator's WiFi.
Despite there's adb commands alike svc wifi enable and svc wifi disable, the password for the default network likely is unknown in /data/misc/wifi/wpa_supplicant.conf; see Connecting to WiFi using adb shell. Since the emulator is rooted, one can generally configure any network alike that, while it is accessible (which the regular WiFi, which is exists in reality, obviously isn't). I think the first one approach is better, because editing emulator images isn't too portable.
AVD manager doesn't provide any ways to customize the simulated Wi-Fi access point AndroidWifi .
You may have to disable it and use another wifi simulator such as this one. It does need the Xposed framework in order to function. Here is how you can configure it.
You can modify the hostapd.conf file in your device (/data/vendor/wifi/hostapd/hostapd.conf). It will allow you to set ssid (ssid=) or even to set a password (wpa_passphrase). You will need a root access to do that.
More details at https://wiki.gentoo.org/wiki/Hostapd#WiFi_Technology
I am developing a wifi search application. Whenever the device is in aeroplane mode wifi is turned off automatically. I found that system apps can turn on the wifi even if the device is in aeroplane mode. I am testing it on Android 9. How do I make my app can able to turn on the wifi?
In android 9, you cannot turn on wifi programmatically when the device is in airplane mode or is tethering hotspot. In this case, the
boolean retVal = mWifiManager.setWifiEnabled(true);
always returns false as the device is in airplane mode. But I've found an unethical way to do it. Not sure even if is it good to do it this way. Works for me.
if(myWifiManager.isWifiEnabled()){
System.out.println("Toggle Wifi Enabled going to disable");
myWifiManager.setWifiEnabled(false);
}
else{
System.out.println("Wifi Disabled going to enable ");
if(Settings.System.getInt(context.getContentResolver(),Settings.System.AIRPLANE_MODE_ON, 0) != 0){
Runtime.getRuntime().exec("adb shell settings put global airplane_mode_radios cell,nfc,wimax,bluetooth");
}
myWifiManager.setWifiEnabled(true);
System.out.println("WI: "+myWifiManager.isWifiEnabled());
}
Explanation for the adb command is here. As mentioned in the link, you can turn things back to how they were by adding the following code when the airplane mode is switched off.
Runtime.getRuntime().exec("adb shell settings delete global airplane_mode_radios");
I have Two buttons to disable WIFI and GPS functionality. On Clicking on button user will not allowed to change the state of gps or wifi. it has to completely block the wifi and gps. Any one having solutions?
WifiManager wifiManager = (WifiManager)this.context.getSystemService(Context.WIFI_SERVICE);
wifiManager.setWifiEnabled(status);
also, add permission. You can find the details from here
You also need the following permissions in your manifest file:
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
WifiManager wifiManager = (WifiManager) this.context.getSystemService(Context.WIFI_SERVICE);
wifiManager.setWifiEnabled(status);
to Block wifi Completely we need a Broadcast receiver who will detect the event for wifi status change. And if the status is on we need to make it off.. by this i resoled it issue.
So I've created the majority of my application but I am having an issue with power saving applications interfering with it. I use the AlarmManager to run a piece of code that send information to a server every x minutes (minimum 1h), the main issue I am having is that power managers are disabling with WiFi because the device is sleeping.
What's the most effective way to ensure WiFi is available at wakeup? Is it to simply enable WiFi and reconnect it?
Maybe an other way to your solution is to listen for the connection_changed intents. That way you know there is a connection to the internet and you can upload.
You can also enable WiFi but you will need permissions for that: (I guess these)
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"></uses-permission>
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE"></uses-permission>
WifiManager wifi = (WifiManager) getSystemService(Context.WIFI_SERVICE);
wifi.setWifiEnabled(enabled);
Haven't tried it but this should do the trick.
While disconnectiong to the selected wifi AP, my WiFi is turned off.I want to keep my WiFi always turn on while disconnecting to the the selected AccessPoint and in the meantime WiFi is n't trying to connect to other AP also.Iam using Android 1.5.Is there any solution for this?
Regards,
Rajendar
mWifi = ((WifiManager)getSystemService( WIFI_SERVICE )).createWifiLock( WifiManager.WIFI_MODE_FULL , "yourtag" );
mWifi.acquire();
// when done
mWifi.release();