gowri
gowri

Reputation: 681

Wi-Fi Availability check in background process android

I'm developing an application with the Wireless activity. I have to work with the internet by using the WLAN(Wireless LAN) and my Bluetooth activity needs to work all the time.

Here, some times i got the problem with my wi-fi / Bluetooth device as Out-of coverage area. I have worked with out the knowledge of this and while submitting the process i came to know that Internet not Available..

I need to update the data every time while i processed in the application. If i have a Wi-fi / Bluetooth Streangth notification embedded in my program or application means i could come to know, if the Wi-fi / Bluetooth streangth went to low.

Help me to resolve this Problem. Thank you..

Upvotes: 0

Views: 426

Answers (2)

JustDanyul
JustDanyul

Reputation: 14044

I think you are asking how to check if your WiFi is connected, if so you can use ConnectivityManager

ConnectivityManager conman = (ConnectivityManager)
     getSystemService(CONNECTIVITY_SERVICE);
NetworkInfo wifi = conman.getNetworkInfo(ConnectivityManager.TYPE_WIFI);

if(wifi.isConnected()) {
   // yay! your connected
}

Now, to have the above running in the background, you can implement the above in a service running in the background and communicating with your activity. Look here for an example to help you get started with background services.

http://android-codes-examples.blogspot.co.uk/2011/11/running-service-in-background-on.html

In a service, you will need to get the ConnectivityManager the following way, since you need to get the application context first

ConnectivityManager conman = (ConnectivityManager)
     getApplicationContext().getgetSystemService(CONNECTIVITY_SERVICE);

Upvotes: 3

Roy James Schumacher
Roy James Schumacher

Reputation: 646

going by what @JustDanyul said you could simply modify the it so that its always checks its connectivity by using a while loop instead of an if statement so that while your connected to the internet your app does one thing and then when disconnected do something else

Upvotes: 0

Related Questions