Football Fans: Download the 2012 Schedule App from Google Play!


Go Back   Android Forums > Android Development > Application Development

Application Development Dev Lounge for the Coder Folks



Reply
 
LinkBack Thread Tools
Old January 16th, 2012, 05:09 PM   #1 (permalink)
New Member
 
Join Date: Nov 2010
Posts: 2
 
Device(s):
Thanks: 0
Thanked 0 Times in 0 Posts
Default Connectivity state in a service

Hi,
I am trying to find a way to get the connectivity state in a service, found the code below but getSystemService is red underlined.
Thanks

public boolean isOnline() {
ConnectivityManager cm = (ConnectivityManager) this.getSystemService(Context.CONNECTIVITY_SERVICE );
return cm.getActiveNetworkInfo().isConnectedOrConnecting( );
}

scanetuk is offline  
Reply With Quote
Sponsors
Old January 19th, 2012, 04:34 PM   #2 (permalink)
Junior Member
 
Lemoncog's Avatar
 
Join Date: Feb 2011
Posts: 25
 
Device(s): HTC Desire HD
Thanks: 0
Thanked 6 Times in 2 Posts
Default

Could you elaborate?
Lemoncog is offline  
Reply With Quote
Old January 20th, 2012, 03:46 PM   #3 (permalink)
New Member
 
Join Date: Nov 2010
Posts: 2
 
Device(s):
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Got an android service running and first thing I would like it to do is check for a network connection, I found another snippet below but don't know how to pass a context to it??

private boolean isOnline(Context context) {
ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERV ICE);
NetworkInfo network = cm.getActiveNetworkInfo();
if (network != null) {
return network.isAvailable();
}
return false;
}



if (isOnline(???))
{
//Code here
}

also this could be running long after the activity is destroyed, I am really not sure only started coding in Android 2 weeks ago.
Thanks for your help
scanetuk is offline  
Reply With Quote
Reply

Bookmarks


Go Back   Android Forums > Android Development > Application Development User CP
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -5. The time now is 12:07 PM.
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.
Custom vBulletin Skins by: Relivo