• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps Conditionally Display Image

racshot65

Lurker
Hi,

I want to conditionally display a image based on whether or not the user is connected to the internet.

I know how to check if the user is connected to the internet or not, what I can't figure out is the conditional image display ?


I want something like:

if( connected )
display(green.jpg)

else
display(red.jpg)


Any pointers on how to do it ?


Thank You
 
Something like this should do the trick:

Code:
ConnectivityManager connectivityMgr = (ConnectivityManager) getApplicationContext().getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo info = connectivityMgr.getActiveNetworkInfo();
if(info!=null && info.isConnectedOrConnecting())
     display(green.jpg)
else
     display(red.jpg)
 
Something like this should do the trick:

Code:
ConnectivityManager connectivityMgr = (ConnectivityManager) getApplicationContext().getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo info = connectivityMgr.getActiveNetworkInfo();
if(info!=null && info.isConnectedOrConnecting())
     display(green.jpg)
else
     display(red.jpg)

Hi,

Thanks for your reply. I have the next work connectivity check worked out. What I'm struggling with is the display(green.jpg) and display(red.jpg)

How do I display those images ?
 
Back
Top Bottom