Android Detect Internet Connection Status
In most of the application running in android needs internet.So it is very important in every application to check whether the internet is available or not.
STEP BY STEP
1.Create a new Android Project.
2.After creating the project,add the required permissions in your
AndroidManifest.xml file.
AndroidManifest.xml file.
- To access the internet we need internet permission.
- To detect network status we need ACCESS_NETWORK_STATE permission.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.detectinternetconnection"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="8" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<activity
android:name=".AndroidDetectInternetConnectionActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
<!-- Internet Permissions -->
<uses-permission android:name="android.permission.INTERNET" />
<!-- Network State Permissions -->
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
</manifest>
- To add the permission manually.Take AndroidManifest.xml
- Then take Permissions-->Add-->Uses Permissions-->Select the required permissions from the combo box provided.
3.Create a class file named as ConnectionDetector.java and apply the
following code.
following code.
4.Whenever user needs to check the internet connection,we use the function
called isConnectingToInternet()
5.In this tutorial,i am placing a button to show the internet status by a click.
6.Open the main.xml file and copy the bellow code.
|
1 comments:
Thanks alot
After a long search i found ur blog
Post a Comment