In my app i have to known wifi status automatically that user is connected to Wifi or not without user action. Also I want to detect when user doesn't use app. Is there any way? I'm new to Android.
Asked
Active
Viewed 258 times
-3
-
Good day This post might help : http://stackoverflow.com/questions/3841317/how-to-see-if-wifi-is-connected-in-android – Tim Botha Nov 10 '14 at 09:11
-
check android documents http://developer.android.com/training/monitoring-device-state/connectivity-monitoring.html#MonitorChanges – Kirtan Nov 10 '14 at 09:21
2 Answers
2
The best that worked for me:
AndroidManifest
<receiver android:name="com.AEDesign.communication.WifiReceiver" >
<intent-filter android:priority="100">
<action android:name="android.net.wifi.STATE_CHANGE" />
</intent-filter>
</receiver>
BroadcastReceiver class
public class WifiReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
NetworkInfo info = intent.getParcelableExtra(WifiManager.EXTRA_NETWORK_INFO);
if(info != null) {
if(info.isConnected()) {
// Do your work.
// e.g. To check the Network Name or other info:
WifiManager wifiManager = (WifiManager)context.getSystemService(Context.WIFI_SERVICE);
WifiInfo wifiInfo = wifiManager.getConnectionInfo();
String ssid = wifiInfo.getSSID();
}
}
}
}
On recive will gets called automatically.

Piyush
- 1,973
- 1
- 19
- 30
0
WifiManager wifi = (WifiManager)getSystemService(Context.WIFI_SERVICE);
if (wifi.isWifiEnabled()){
//wifi is enabled
}
For details check here
or
ConnectivityManager connManager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo networkInfo = connManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
if (networkInfo.isConnected()) {
// Do whatever
}

Harsha Vardhan
- 3,324
- 2
- 17
- 22