Vous êtes sur la page 1sur 2

5/30/2011

Android snippet: Check if the device is co

PROGRAMMER XR
JUST SOMEONE WHO EXPLAINS ANDROID CODE!
Subscribe via RSS
HOME ANDROID TUTORIALS NEED HELP ON A PROJECT ? FOLLOW @ANDROIDPXR

Android snippet: Check if the device is connected to the internet


MAY/11

Past codings 2011 (34) May (9)

Just a quick function to make your live easier Bart added a comment to the XML + ProgressBar post from yesterday that checks is the device that runs your application has an active internet connection. To make sure its properly searchable i chose to repost it as an Android snippet. If you guys come across more useful little pieces of code. Just contact me or leave a comment below.
Boo!

Android tip: Emulator key binding Android tutorial: Game menu with Android snippet: Check if the dev Merging 2 tutorials: XML data &am Project spotlight: Pull down to r Android development tutorial: rea Android tutorial: How to make a b Implementing Facebook into your A Android tutorial: How to make a s April (8) March (11) February (6) 2010 (14)

Here is the function


1 2 3 4 5 6 7 8 private Boolean isOnline() { ConnectivityManager cm = (ConnectivityManager)getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo ni = cm.getActiveNetworkInfo(); if(ni != null && ni.isConnected()) return true; return false; }

Also don't forget to add the INTERNET (and ACCESS_NETWORK_STATE) permissions to you application
1 2 <uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

OSS Fast Infoset Tools Fast, compact XML without a schema Ideal for embedded devices. Evals.
www.oss.com

2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1

Verbatim/Text Coding Ascribe is the world's most popular survey verbatim coding application.
www.languagelogic.info

Topics Android news Android tutorials Javascript / Ajax Other programming stuff :) PHP / HTML Project spotlight

Tagged as: android, snippet

Leave a comment

Recent Posts Comments (1) Trackbacks (0) ( subscribe to comments on this post ) Android tip: Emulator key bindings

Bart
May 24th, 2011 - 04:52

Android tutorial: Game menu with a custom Font Android snippet: Check if the device is connected to the internet Merging 2 tutorials: XML data & ProgressDialog using ASyncTask

Dont forget to add the ACCES_NETWORK_STATE permission! You need that aswell to check for an internet connection:

p-xr.com/android-snippet-check-if-the-d

1/2

5/30/2011

Android snippet: Check if the device is co

ProgressDialog using ASyncTask Project spotlight: Pull down to refresh ( like the official Twitter client )

Leave a comment
Name (required) Email (required) W ebsite

A penny for my thoughts

Support me and help me finance my tablet so that i can make more Honeycomb tutorials

Submit
Android tutorial: Game menu with a custom Font Merging 2 tutorials: XML data & ProgressDialog using ASyncTask

Generation of Source Code .NET, Java, C++, XSD, DDL, PHP, CORBA, Python & more. Free Trial!
www.spa rx syste m s.com

Mature Ajax RIA Chosen by top software vendors. View 200+ examples & full docs
www.Sm artC lie nt.com

Run your apps as services Run any applic ation or batch as a Windows system servic e
www.active plus.co m

.netCART for ASP.NET shopping c art with real- time ship / payment proc essing and free trial.
www.do tne tca rt.co m

Flowcharts for C# and VB Edit, analyse, display and layout flowcharts and networks
www.ywo rk s.com

Warning: preg_match()ndrei Luca Lightword Theme by A [function.preg-match]: Compilation failed: nothing to repeat at offset 1 in /home/markmooi/domains/p-xr.com/public_html/wpcontent/plugins/wassup/wassup.php on line 3954 Warning: preg_match() [function.preg-match]: Compilation failed: nothing to repeat at offset 1 in /home/markmooi/domains/p-xr.com/public_html/wpcontent/plugins/wassup/wassup.php on line 3954

C opyright 2011 Programmer XR Powered by W ordPress

Go to top

p-xr.com/android-snippet-check-if-the-d

2/2

Vous aimerez peut-être aussi