简体   繁体   中英

Turn off/on wifi by wifi automatically by geolocation in Android

In my application I want to implement this feature: Turn Off or Turn On the wifi using the geolocation.

I mean, for example, when I come back home my wifi turn on and when go away it turns off. It would be best if the user gives the location as input. Does anyone have any sample code about it? For now to me even if the location is written by me directly in Java it's good too.

Just incase anyone still encounters this issue, and wishes to use different approach, you can use this open source git project , which uses a sdk (which is free of charge).

Bassically, this is close to what you need :

  1. When user left home, the wifi is disabled.
  2. When user arrive to work, the wifi is enabled.

In this sample, your user can declare his home, and then the wifi disabling will happen when the user arrives home.

You can use this sdk for many locations such as : home, work, gym, super market, mall, etc..

设为首页

I do not know about geo location, but turning Wifi on/off can be done using the code below

WifiManager wifiManager = (WifiManager) getBaseContext().getSystemService(Context.WIFI_SERVICE);

To Enable

wifiManager.setWifiEnabled(true);

To Disable

wifiManager.setWifiEnabled(false);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM