Network


 

  1. Check Internet Connection
  2. Check WiFi Connection
  3. Traffic Statics
  4. WiFi Info
  5. AndroidHttpClient
  6. DefaultHttpClient
  7. HttpUrlConnection
  8. Passing Parameters via GET
  9. Passing Parameters via POST
  10. Passing Parameters as JSON Data
  11. Basic Authentication

 

1. Check Internet Connection
Step 1 : Select File -> New -> Project -> Android Application Project. Fill the forms, create “Blank Activity” and click “Finish” button.
Step 2 : Open res -> layout -> activity_main.xml and add following code :

Step 3 : Open src -> package -> MainActivity.java and add following code :

Step 4 : Open Create new Class, ConnectionDetector.java and add following code :

Step 5 : Open AndroidManifest.xml and add following code :

ScreenShot:

internet no_internet

Download_button

 

2. Check WiFi Connection
Step 1 : Select File -> New -> Project -> Android Application Project. Fill the forms, create “Blank Activity” and click “Finish” button.
Step 2 : Open res -> layout -> activity_main.xml and add following code :

Step 3 : Open src -> package -> MainActivity.java and add following code :

Step 4 : Open Create new Class, WifiConnection.java and add following code :

Step 5 : Open AndroidManifest.xml and add following code :

ScreenShot:

wifi no_wifi

Download_button

 

3. Traffic Statics
Step 1 : Select File -> New -> Project -> Android Application Project. Fill the forms, create “Blank Activity” and click “Finish” button.
Step 2 : Open res -> layout -> activity_main.xml and add following code :

Step 3 : Open src -> package -> MainActivity.java and add following code :

Step 4 : Open AndroidManifest.xml and add following code :

ScreenShot:

load_traffics load_traffics2

Download_button

 

4. WiFi Info
Step 1 : Select File -> New -> Project -> Android Application Project. Fill the forms, create “Blank Activity” and click “Finish” button.
Step 2 : Open res -> layout -> activity_main.xml and add following code :

Step 3 : Open src -> package -> MainActivity.java and add following code :

Step 4 : Open AndroidManifest.xml and add following code :

ScreenShot:

wifi2

Download_button

 

5. AndroidHttpClient
Step 1 : Select File -> New -> Project -> Android Application Project. Fill the forms, create “Blank Activity” and click “Finish” button.
Step 2 : Open res -> layout -> activity_main.xml and add following code :

Step 3 : Open src -> package -> MainActivity.java and add following code :

Step 4 : Open src -> package -> Create new class, MyAndroidHttpClient.java and add following code :

Step 5 : Open AndroidManifest.xml and add following code :

ScreenShot:

android_hhtp android_hhtp3 android_hhtp2

Download SourceCode

 

6. DefaultHttpClient
Step 1 : Select File -> New -> Project -> Android Application Project. Fill the forms, create “Blank Activity” and click “Finish” button.
Step 2 : Open res -> layout -> activity_main.xml and add following code :

Step 3 : Open src -> package -> MainActivity.java and add following code :

Step 4 : Open src -> package -> Create new class, .java and add following code :

Step 5 : Open AndroidManifest.xml and add following code :

ScreenShot:

default_client3 default_client default_client2

Download SourceCode

 

7. HttpUrlConnection
Step 1 : Select File -> New -> Project -> Android Application Project. Fill the forms, create “Blank Activity” and click “Finish” button.
Step 2 : Open res -> layout -> activity_main.xml and add following code :

Step 3 : Open src -> package -> MainActivity.java and add following code :

Step 4 : Open src -> package -> Create new class, .java and add following code :

Step 5 : Open AndroidManifest.xml and add following code :

ScreenShot:

http_url3 http_url2 http_url

Download SourceCode

 

8. Passing Parameters via GET
Step 1 : Select File -> New -> Project -> Android Application Project. Fill the forms, create “Blank Activity” and click “Finish” button.
Step 2 : Open res -> layout -> activity_main.xml and add following code :

Step 3 : Open src -> package -> MainActivity.java and add following code :

Step 4 : Open src -> package -> Create new class, MyHttpURLConnection.java and add following code :

Step 5 : Open src -> package -> Create new class, RequestPackage.java and add following code :

Step 6 : Open AndroidManifest.xml and add following code :

Step 7 : Create display_received_params.php file, copy paste this code and upload it to the server:

ScreenShot:

params_post params_get

Download SourceCode

 

8. Passing Parameters via POST
Step 1 : Select File -> New -> Project -> Android Application Project. Fill the forms, create “Blank Activity” and click “Finish” button.
Step 2 : Open res -> layout -> activity_main.xml and add following code :

Step 3 : Open src -> package -> MainActivity.java and add following code :

Step 4 : Open src -> package -> Create new class, MyHttpURLConnection.java and add following code :

Step 5 : Open src -> package -> Create new class, RequestPackage.java and add following code :

Step 6 : Open AndroidManifest.xml and add following code :