0
Android Application Development<br />Android and Internet<br />Ahsanul Karim<br />ahsanul.karim@sentinelbd.com<br />Sentin...
Connecting to the Internet<br />Http Connection Example<br />In this example we’ll see:<br />How to use HttpClient object ...
Connecting to the Internet<br />Http Connection Example<br />We’ll create a simple project to see HTTP Connection Example<...
Connecting to the Internet<br />Http Connection Example<br />We’ll start with a class named HttpRetriever.<br />In this cl...
Connecting to the Internet<br />Http Connection Example<br />Now from our main Activity, we’ll use this class. To input th...
Connecting to the Internet<br />Http Connection Example<br />Now we start with UI components<br />
Connecting to the Internet<br />Http Connection Example<br />On button’s action, we add:<br />
Connecting to the Internet<br />Http Connection Example<br />Now we run<br />
Connecting to the Internet<br />Http Connection Example<br />Now we need to add some checks for internet connection <br />
Connecting to the Internet<br />How to connect MySQL DB on Web server<br />We have: <br />a database named httptest<br />a...
Connecting to the Internet<br />How to connect MySQL DB on Web server<br />As response we get JSON data:<br />[<br />{“id”...
Connecting to the Internet<br />Parsing JSON Data<br />
Upcoming SlideShare
Loading in...5
×

Client-Server

4,676

Published on

Published in: Education, Technology
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
4,676
On Slideshare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
138
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Transcript of "Client-Server"

  1. 1. Android Application Development<br />Android and Internet<br />Ahsanul Karim<br />ahsanul.karim@sentinelbd.com<br />Sentinel Solutions Ltd.<br />http://www.sentinelbd.com<br />
  2. 2. Connecting to the Internet<br />Http Connection Example<br />In this example we’ll see:<br />How to use HttpClient object to send http requests<br />How to get response data and show them<br />For manipulating HTTP requests/responses in an Android environment, the standard classes <br />from the java.net package can be used. <br />Thus, classes such as URL, URLConnection, HttpURLConnection etc., can all be used in the <br />known way.<br />
  3. 3. Connecting to the Internet<br />Http Connection Example<br />We’ll create a simple project to see HTTP Connection Example<br />We create a project with following:<br />Project Name: HttpConnectionDemo<br />Build Target: 1.6<br />Application name:HttpConnectionDemo<br />Package name: <br />com.basistraining.httpdemo<br />Create Activity:<br />HttpConnectionDemoActivity<br />Min SDK Version: 4<br />Add INTERNET permission<br />
  4. 4. Connecting to the Internet<br />Http Connection Example<br />We’ll start with a class named HttpRetriever.<br />In this class method: String retrieve (String url) will do the work<br />
  5. 5. Connecting to the Internet<br />Http Connection Example<br />Now from our main Activity, we’ll use this class. To input the url we make a layout<br />
  6. 6. Connecting to the Internet<br />Http Connection Example<br />Now we start with UI components<br />
  7. 7. Connecting to the Internet<br />Http Connection Example<br />On button’s action, we add:<br />
  8. 8. Connecting to the Internet<br />Http Connection Example<br />Now we run<br />
  9. 9. Connecting to the Internet<br />Http Connection Example<br />Now we need to add some checks for internet connection <br />
  10. 10. Connecting to the Internet<br />How to connect MySQL DB on Web server<br />We have: <br />a database named httptest<br />a table named users with following fields<br />Id (integer)<br />name (VARCHAR (50))<br />email (VARCHAR (50))<br />lat (VARCHAR (50))<br />long (VARCHAR (50))<br />We keep a very simple code in server side- connect to the database- run an SQL query- output it in JSON format<br />
  11. 11. Connecting to the Internet<br />How to connect MySQL DB on Web server<br />As response we get JSON data:<br />[<br />{“id”:”1”,<br />"name":"john",<br /> "email":"john@a.com",<br /> "lat":"23.4567",<br /> "long":"90.86777"},<br />{“id”:”2”,<br />"name":"smith",<br /> "email":"smith@b.com",<br /> "lat":"23.6767",<br /> "long":"90.986765"}<br />]<br />
  12. 12. Connecting to the Internet<br />Parsing JSON Data<br />
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×