tags:

views:

564

answers:

2

I would need to check the wifi is on or off in the phone at the runtime?

if it is not connected, i want to show dialog and goto directly Setting/Wireless Controls to enable it by user.

its for both wifi and Gps staus of the phone. How to do it? which intent to wake for this? Any idea?

+2  A: 

You can use the WifiManager class to get the state of Wi-Fi.

See this question for opening Wi-Fi settings. And this question for GPS status.

kgiannakakis
how to trace the status of GPS?
Praveen Chandrasekaran
See the link in my edited answer.
kgiannakakis
+1  A: 

To check if the device is connected via mobile or wifi you can use this code:

ConnectivityManager conMan = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);

//mobile
State mobile = conMan.getNetworkInfo(0).getState();

//wifi
State wifi = conMan.getNetworkInfo(1).getState();

and then use it like that:

if (mobile == NetworkInfo.State.CONNECTED || mobile == NetworkInfo.State.CONNECTING) {
    //mobile
} else if (wifi == NetworkInfo.State.CONNECTED || wifi == NetworkInfo.State.CONNECTING) {
    //wifi
}
Roflcoptr
how to trace the status of GPS?
Praveen Chandrasekaran
There's no guarantee that the mobile is networkInfo 0 and the wifi will be network info 1. Might be better to check the type of what's returned by 'getActiveNetworkInfo'
haseman