SlideShare uma empresa Scribd logo
1 de 32
Baixar para ler offline
Intro to
Android Development 3
Accessibility Capstone
Nov 29, 2011
Outline
• Web Services
• XML vs. JSON
• Your Own Web Service
Hello, Android
The key to the capstone… (sort of)
Using Web Services
HTTP Request
HTTP Response
Using Web Services
HTTP Request
HTTP Response
Using Web Services
HTTP Request
HTTP Response
webserver
some
program
Why use a web service?
An HTTP Request
http://www.google.com
An HTTP Request
http://www.google.com
http://www.geonames.org/
An HTTP Request
http://www.google.com
http://www.geonames.org/
http://ws.geonames.org/wikipediaSearch?q=l
ondon&maxRows=10
An HTTP Request
http://www.google.com
http://www.geonames.org/
http://ws.geonames.org/wikipediaSearch?q=l
ondon&maxRows=10
Adding parameters:
?param1=val1&param2=val2
An HTTP Response
• Response code
2xx = success! 
4xx = client error
5xx = server error
An HTTP Response
• Response code
2xx = success! 
4xx = client error
5xx = server error
• Response body (XML, JSON)
<geonames>
<entry>
<lang>en</lang>
<title>London</title>
<summary>
London (; and largest urban area of England and the United Kingdom. At its core,
the ancient City of London, to which the name historically belongs, still retains its
limited mediaeval boundaries; but since at least the 19th century the name
"London" has also referred to the whole metropolis which has developed around
XML and JSON
• Parsers
– XML: Different traversals include SAX, DOM, etc.
– JSON: Look at JSONObject/JSONArray classes
• Overviews
– http://www.w3schools.com/json/
– http://www.w3schools.com/xml/
• Recommend using JSON: small, easy to parse,
fast
XML
<?xml version="1.0"?>
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>
JSON
{
"employees": [
{ "firstname":"John" , "lastname":"Doe" },
{ "firstname":"Anna" , "lastname":"Smith" },
{ "firstname":"Peter" , “lastname":"Jones" }
]
}
JSON
• Name/Value Pairs: “name” : “value”
– "firstname":"John"
• JSON Objects: , … -
– { "firstname":"John" , "lastname":"Doe" }
• JSON Arrays: * …, …, … +
[
{ "firstname":"John" , "lastname":"Doe" },
{ "firstname":"Anna" , "lastname":"Smith" },
…
]
How to Use a Webservice
• Find a webservice or write your own
example: www.geonames.org
• Construct the URL
add parameters, extra headers (if needed
• Execute the request asynchronously
• Check the response code
200 = success, 4xx = client error, 5xx = server error
• Parse the response body
Construct the URL
final static String PLACE_NAME = "Seattle";
final static String URL = “http://ws.geonames.org/” +
“wikipediaSearch?q=" + PLACE_NAME + "&maxRows=4";
Execute the Request
public String callWebService(){
HttpClient httpclient = new DefaultHttpClient();
HttpGet request = new HttpGet(URL);
String result = "";
ResponseHandler<String> handler =
new BasicResponseHandler();
try {
result = httpclient.execute(request, handler);
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
httpclient.getConnectionManager().shutdown();
return result;
}
Execute the Request
public String callWebService(){
HttpClient httpclient = new DefaultHttpClient();
HttpGet request = new HttpGet(URL);
String result = "";
ResponseHandler<String> handler =
new BasicResponseHandler();
try {
result = httpclient.execute(request, handler);
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
httpclient.getConnectionManager().shutdown();
return result;
}
the client will open a connection
and executes the request
Execute the Request
public String callWebService(){
HttpClient httpclient = new DefaultHttpClient();
HttpGet request = new HttpGet(URL);
String result = "";
ResponseHandler<String> handler =
new BasicResponseHandler();
try {
result = httpclient.execute(request, handler);
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
httpclient.getConnectionManager().shutdown();
return result;
}
request object contains URL
Execute the Request
public String callWebService(){
HttpClient httpclient = new DefaultHttpClient();
HttpGet request = new HttpGet(URL);
String result = "";
ResponseHandler<String> handler =
new BasicResponseHandler();
try {
result = httpclient.execute(request, handler);
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
httpclient.getConnectionManager().shutdown();
return result;
}
this kind of response handler will
return the response body as a string if
the request was successful
Execute the Request
public String callWebService(){
HttpClient httpclient = new DefaultHttpClient();
HttpGet request = new HttpGet(URL);
String result = "";
ResponseHandler<String> handler =
new BasicResponseHandler();
try {
result = httpclient.execute(request, handler);
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
httpclient.getConnectionManager().shutdown();
return result;
}
executes the request and processes the
response using the handler
Execute the Request
public String callWebService(){
HttpClient httpclient = new DefaultHttpClient();
HttpGet request = new HttpGet(URL);
String result = "";
ResponseHandler<String> handler =
new BasicResponseHandler();
try {
result = httpclient.execute(request, handler);
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
httpclient.getConnectionManager().shutdown();
return result;
}
generated by the handler
Calling on callWebService() and
Displaying the Results
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
TextView tv = (TextView) findViewById(R.id.resultTV);
String result = callWebService();
tv.setText(result);
}
What’s wrong with the example?
What’s wrong with the example?
• result = httpclient.execute(request, handler);
blocks and waits for entire page to download!
• Solution: threads
– You may have to use another thread in your
application!
– java.util.concurrent package
– Good example in Hello, Android (web services
chapter)
– Keeping it all simple is key, then program away
Your Own Web Service
• May need if…
– You need additional processing power
– You want to tie phone app into a web product
– Etc…
• If you create your own web service…
– Server Side Scripting (PHP, Ruby on Rails, etc.)
– Web server (abstract.cs, etc.)
Your Own Web Service
• Very Basic PHP Overview:
1. Create .php page
(http://foo.com/service.php)
2. Use $_GET*‘param’+
(http://foo.com/service.php?param=helloworld
3. Do stuff with the parameters
($bar = $_GET*‘param’+ )
4. Format output into XML or JSON or whatever you
need
(echo $bar)
• Phone app will visit php page and get its result
Other Topics
• GPS and Sensors
– LocationManager
• SQL Database
– SQLiteDatabase
• Camera
• Multitouch
Exercise
Develop an application that uses a web
service that is accessible to a blind person.
For extra brownie points: use the GPS!
-Use TTS to make the application accessible.
-Find a web service (you can start from Geonames)
-Find and use a Java XML parser to parse the response body
(you can try SAX)
Note: many web services use JSON, not XML.

Mais conteúdo relacionado

Mais procurados

Azure SQL Database - Connectivity Best Practices
Azure SQL Database - Connectivity Best PracticesAzure SQL Database - Connectivity Best Practices
Azure SQL Database - Connectivity Best PracticesJose Manuel Jurado Diaz
 
Trisha gee concurrentprogrammingusingthedisruptor
Trisha gee concurrentprogrammingusingthedisruptorTrisha gee concurrentprogrammingusingthedisruptor
Trisha gee concurrentprogrammingusingthedisruptorEthanTu
 
Enhanced Web Service Testing: A Better Mock Structure
Enhanced Web Service Testing: A Better Mock StructureEnhanced Web Service Testing: A Better Mock Structure
Enhanced Web Service Testing: A Better Mock StructureCRMScienceKirk
 
The Road To Reactive with RxJava JEEConf 2016
The Road To Reactive with RxJava JEEConf 2016The Road To Reactive with RxJava JEEConf 2016
The Road To Reactive with RxJava JEEConf 2016Frank Lyaruu
 
Testing RESTful Webservices using the REST-assured framework
Testing RESTful Webservices using the REST-assured frameworkTesting RESTful Webservices using the REST-assured framework
Testing RESTful Webservices using the REST-assured frameworkMicha Kops
 
JavaOne 2013: Java 8 - The Good Parts
JavaOne 2013: Java 8 - The Good PartsJavaOne 2013: Java 8 - The Good Parts
JavaOne 2013: Java 8 - The Good PartsKonrad Malawski
 
JSON Rules Language
JSON Rules LanguageJSON Rules Language
JSON Rules Languagegiurca
 
DOM-based Test Adequacy Criteria for Web Applications
DOM-based Test Adequacy Criteria for Web ApplicationsDOM-based Test Adequacy Criteria for Web Applications
DOM-based Test Adequacy Criteria for Web ApplicationsSALT Lab @ UBC
 
Python: the coolest is yet to come
Python: the coolest is yet to comePython: the coolest is yet to come
Python: the coolest is yet to comePablo Enfedaque
 
Load Testing with PHP and RedLine13
Load Testing with PHP and RedLine13Load Testing with PHP and RedLine13
Load Testing with PHP and RedLine13Jason Lotito
 
Callbacks, promises, generators - asynchronous javascript
Callbacks, promises, generators - asynchronous javascriptCallbacks, promises, generators - asynchronous javascript
Callbacks, promises, generators - asynchronous javascriptŁukasz Kużyński
 
Pushing Datatothe Browserwith Comet Ajax W
Pushing Datatothe Browserwith Comet Ajax WPushing Datatothe Browserwith Comet Ajax W
Pushing Datatothe Browserwith Comet Ajax Wrajivmordani
 
Avoiding callback hell in Node js using promises
Avoiding callback hell in Node js using promisesAvoiding callback hell in Node js using promises
Avoiding callback hell in Node js using promisesAnkit Agarwal
 
13 networking, mobile services, and authentication
13   networking, mobile services, and authentication13   networking, mobile services, and authentication
13 networking, mobile services, and authenticationWindowsPhoneRocks
 
Is writing performant code too expensive?
Is writing performant code too expensive? Is writing performant code too expensive?
Is writing performant code too expensive? Tomasz Kowalczewski
 
トークンリフレッシュ処理を含むAPIClientのテスト #hakata_test_night
トークンリフレッシュ処理を含むAPIClientのテスト #hakata_test_nightトークンリフレッシュ処理を含むAPIClientのテスト #hakata_test_night
トークンリフレッシュ処理を含むAPIClientのテスト #hakata_test_nightKenji Tanaka
 
Asynchronous programming done right - Node.js
Asynchronous programming done right - Node.jsAsynchronous programming done right - Node.js
Asynchronous programming done right - Node.jsPiotr Pelczar
 
Statying Alive - Online and OFfline
Statying Alive - Online and OFflineStatying Alive - Online and OFfline
Statying Alive - Online and OFflineErik Hellman
 
$q and Promises in AngularJS
$q and Promises in AngularJS $q and Promises in AngularJS
$q and Promises in AngularJS a_sharif
 

Mais procurados (20)

Azure SQL Database - Connectivity Best Practices
Azure SQL Database - Connectivity Best PracticesAzure SQL Database - Connectivity Best Practices
Azure SQL Database - Connectivity Best Practices
 
Trisha gee concurrentprogrammingusingthedisruptor
Trisha gee concurrentprogrammingusingthedisruptorTrisha gee concurrentprogrammingusingthedisruptor
Trisha gee concurrentprogrammingusingthedisruptor
 
Enhanced Web Service Testing: A Better Mock Structure
Enhanced Web Service Testing: A Better Mock StructureEnhanced Web Service Testing: A Better Mock Structure
Enhanced Web Service Testing: A Better Mock Structure
 
The Road To Reactive with RxJava JEEConf 2016
The Road To Reactive with RxJava JEEConf 2016The Road To Reactive with RxJava JEEConf 2016
The Road To Reactive with RxJava JEEConf 2016
 
Testing RESTful Webservices using the REST-assured framework
Testing RESTful Webservices using the REST-assured frameworkTesting RESTful Webservices using the REST-assured framework
Testing RESTful Webservices using the REST-assured framework
 
JavaOne 2013: Java 8 - The Good Parts
JavaOne 2013: Java 8 - The Good PartsJavaOne 2013: Java 8 - The Good Parts
JavaOne 2013: Java 8 - The Good Parts
 
JSON Rules Language
JSON Rules LanguageJSON Rules Language
JSON Rules Language
 
Springを用いた社内ライブラリ開発
Springを用いた社内ライブラリ開発Springを用いた社内ライブラリ開発
Springを用いた社内ライブラリ開発
 
DOM-based Test Adequacy Criteria for Web Applications
DOM-based Test Adequacy Criteria for Web ApplicationsDOM-based Test Adequacy Criteria for Web Applications
DOM-based Test Adequacy Criteria for Web Applications
 
Python: the coolest is yet to come
Python: the coolest is yet to comePython: the coolest is yet to come
Python: the coolest is yet to come
 
Load Testing with PHP and RedLine13
Load Testing with PHP and RedLine13Load Testing with PHP and RedLine13
Load Testing with PHP and RedLine13
 
Callbacks, promises, generators - asynchronous javascript
Callbacks, promises, generators - asynchronous javascriptCallbacks, promises, generators - asynchronous javascript
Callbacks, promises, generators - asynchronous javascript
 
Pushing Datatothe Browserwith Comet Ajax W
Pushing Datatothe Browserwith Comet Ajax WPushing Datatothe Browserwith Comet Ajax W
Pushing Datatothe Browserwith Comet Ajax W
 
Avoiding callback hell in Node js using promises
Avoiding callback hell in Node js using promisesAvoiding callback hell in Node js using promises
Avoiding callback hell in Node js using promises
 
13 networking, mobile services, and authentication
13   networking, mobile services, and authentication13   networking, mobile services, and authentication
13 networking, mobile services, and authentication
 
Is writing performant code too expensive?
Is writing performant code too expensive? Is writing performant code too expensive?
Is writing performant code too expensive?
 
トークンリフレッシュ処理を含むAPIClientのテスト #hakata_test_night
トークンリフレッシュ処理を含むAPIClientのテスト #hakata_test_nightトークンリフレッシュ処理を含むAPIClientのテスト #hakata_test_night
トークンリフレッシュ処理を含むAPIClientのテスト #hakata_test_night
 
Asynchronous programming done right - Node.js
Asynchronous programming done right - Node.jsAsynchronous programming done right - Node.js
Asynchronous programming done right - Node.js
 
Statying Alive - Online and OFfline
Statying Alive - Online and OFflineStatying Alive - Online and OFfline
Statying Alive - Online and OFfline
 
$q and Promises in AngularJS
$q and Promises in AngularJS $q and Promises in AngularJS
$q and Promises in AngularJS
 

Destaque

Toward the next generation of recommender systems
Toward the next generation of recommender systemsToward the next generation of recommender systems
Toward the next generation of recommender systemsAravindharamanan S
 
From home sql_server_tutorials
From home sql_server_tutorialsFrom home sql_server_tutorials
From home sql_server_tutorialsAravindharamanan S
 
Soa amsterdam-restws-pautasso-talk
Soa amsterdam-restws-pautasso-talkSoa amsterdam-restws-pautasso-talk
Soa amsterdam-restws-pautasso-talkAravindharamanan S
 
Yoda an accurate and scalable web based recommendation systems
Yoda an accurate and scalable web based recommendation systemsYoda an accurate and scalable web based recommendation systems
Yoda an accurate and scalable web based recommendation systemsAravindharamanan S
 
Ppt bigdataanalyticsfinanceprofessionals-big data, business analytics and fin...
Ppt bigdataanalyticsfinanceprofessionals-big data, business analytics and fin...Ppt bigdataanalyticsfinanceprofessionals-big data, business analytics and fin...
Ppt bigdataanalyticsfinanceprofessionals-big data, business analytics and fin...Aravindharamanan S
 
Collaborative recommender systems for building automation
Collaborative recommender systems for building automationCollaborative recommender systems for building automation
Collaborative recommender systems for building automationAravindharamanan S
 
Visual studio-2012-product-guide
Visual studio-2012-product-guideVisual studio-2012-product-guide
Visual studio-2012-product-guideAravindharamanan S
 
Android chapter16-web-services
Android chapter16-web-servicesAndroid chapter16-web-services
Android chapter16-web-servicesAravindharamanan S
 
Web services-synchronous-or-asynchronous
Web services-synchronous-or-asynchronousWeb services-synchronous-or-asynchronous
Web services-synchronous-or-asynchronousAravindharamanan S
 
Big data -_14._maerz_mitarbeiterforschung_kundenevent_v2.pptx__schreibgeschue...
Big data -_14._maerz_mitarbeiterforschung_kundenevent_v2.pptx__schreibgeschue...Big data -_14._maerz_mitarbeiterforschung_kundenevent_v2.pptx__schreibgeschue...
Big data -_14._maerz_mitarbeiterforschung_kundenevent_v2.pptx__schreibgeschue...Aravindharamanan S
 

Destaque (16)

Xml+messaging+with+soap
Xml+messaging+with+soapXml+messaging+with+soap
Xml+messaging+with+soap
 
Recommender systems
Recommender systemsRecommender systems
Recommender systems
 
Toward the next generation of recommender systems
Toward the next generation of recommender systemsToward the next generation of recommender systems
Toward the next generation of recommender systems
 
Cs583 recommender-systems
Cs583 recommender-systemsCs583 recommender-systems
Cs583 recommender-systems
 
From home sql_server_tutorials
From home sql_server_tutorialsFrom home sql_server_tutorials
From home sql_server_tutorials
 
Jax ws
Jax wsJax ws
Jax ws
 
Soa amsterdam-restws-pautasso-talk
Soa amsterdam-restws-pautasso-talkSoa amsterdam-restws-pautasso-talk
Soa amsterdam-restws-pautasso-talk
 
Yoda an accurate and scalable web based recommendation systems
Yoda an accurate and scalable web based recommendation systemsYoda an accurate and scalable web based recommendation systems
Yoda an accurate and scalable web based recommendation systems
 
Ppt bigdataanalyticsfinanceprofessionals-big data, business analytics and fin...
Ppt bigdataanalyticsfinanceprofessionals-big data, business analytics and fin...Ppt bigdataanalyticsfinanceprofessionals-big data, business analytics and fin...
Ppt bigdataanalyticsfinanceprofessionals-big data, business analytics and fin...
 
Collaborative recommender systems for building automation
Collaborative recommender systems for building automationCollaborative recommender systems for building automation
Collaborative recommender systems for building automation
 
Android programming-basics
Android programming-basicsAndroid programming-basics
Android programming-basics
 
Soap binding survey
Soap binding surveySoap binding survey
Soap binding survey
 
Visual studio-2012-product-guide
Visual studio-2012-product-guideVisual studio-2012-product-guide
Visual studio-2012-product-guide
 
Android chapter16-web-services
Android chapter16-web-servicesAndroid chapter16-web-services
Android chapter16-web-services
 
Web services-synchronous-or-asynchronous
Web services-synchronous-or-asynchronousWeb services-synchronous-or-asynchronous
Web services-synchronous-or-asynchronous
 
Big data -_14._maerz_mitarbeiterforschung_kundenevent_v2.pptx__schreibgeschue...
Big data -_14._maerz_mitarbeiterforschung_kundenevent_v2.pptx__schreibgeschue...Big data -_14._maerz_mitarbeiterforschung_kundenevent_v2.pptx__schreibgeschue...
Big data -_14._maerz_mitarbeiterforschung_kundenevent_v2.pptx__schreibgeschue...
 

Semelhante a Android dev 3

Java Web Programming [2/9] : Servlet Basic
Java Web Programming [2/9] : Servlet BasicJava Web Programming [2/9] : Servlet Basic
Java Web Programming [2/9] : Servlet BasicIMC Institute
 
How to make Ajax work for you
How to make Ajax work for youHow to make Ajax work for you
How to make Ajax work for youSimon Willison
 
Bare-knuckle web development
Bare-knuckle web developmentBare-knuckle web development
Bare-knuckle web developmentJohannes Brodwall
 
The Full Power of ASP.NET Web API
The Full Power of ASP.NET Web APIThe Full Power of ASP.NET Web API
The Full Power of ASP.NET Web APIEyal Vardi
 
Test strategy for web development
Test strategy for web developmentTest strategy for web development
Test strategy for web developmentalice yang
 
Asynchronous JavaScript & XML (AJAX)
Asynchronous JavaScript & XML (AJAX)Asynchronous JavaScript & XML (AJAX)
Asynchronous JavaScript & XML (AJAX)Adnan Sohail
 
Google Web Toolkits
Google Web ToolkitsGoogle Web Toolkits
Google Web ToolkitsYiguang Hu
 
Rethinking Syncing at AltConf 2019
Rethinking Syncing at AltConf 2019Rethinking Syncing at AltConf 2019
Rethinking Syncing at AltConf 2019Joe Keeley
 
How to perform debounce in react
How to perform debounce in reactHow to perform debounce in react
How to perform debounce in reactBOSC Tech Labs
 
CTS Conference Web 2.0 Tutorial Part 2
CTS Conference Web 2.0 Tutorial Part 2CTS Conference Web 2.0 Tutorial Part 2
CTS Conference Web 2.0 Tutorial Part 2Geoffrey Fox
 
HTTP Whiteboard - OSGI Compendium 6.0 - How web apps should have been! - R Auge
HTTP Whiteboard - OSGI Compendium 6.0 - How web apps should have been! - R AugeHTTP Whiteboard - OSGI Compendium 6.0 - How web apps should have been! - R Auge
HTTP Whiteboard - OSGI Compendium 6.0 - How web apps should have been! - R Augemfrancis
 
Java web programming
Java web programmingJava web programming
Java web programmingChing Yi Chan
 
Web Component Development Using Servlet & JSP Technologies (EE6) - Chapter 4...
 Web Component Development Using Servlet & JSP Technologies (EE6) - Chapter 4... Web Component Development Using Servlet & JSP Technologies (EE6) - Chapter 4...
Web Component Development Using Servlet & JSP Technologies (EE6) - Chapter 4...WebStackAcademy
 
Implementing Comet using PHP
Implementing Comet using PHPImplementing Comet using PHP
Implementing Comet using PHPKing Foo
 
A language for the Internet: Why JavaScript and Node.js is right for Internet...
A language for the Internet: Why JavaScript and Node.js is right for Internet...A language for the Internet: Why JavaScript and Node.js is right for Internet...
A language for the Internet: Why JavaScript and Node.js is right for Internet...Tom Croucher
 

Semelhante a Android dev 3 (20)

Java Web Programming [2/9] : Servlet Basic
Java Web Programming [2/9] : Servlet BasicJava Web Programming [2/9] : Servlet Basic
Java Web Programming [2/9] : Servlet Basic
 
How to make Ajax work for you
How to make Ajax work for youHow to make Ajax work for you
How to make Ajax work for you
 
Bare-knuckle web development
Bare-knuckle web developmentBare-knuckle web development
Bare-knuckle web development
 
The Full Power of ASP.NET Web API
The Full Power of ASP.NET Web APIThe Full Power of ASP.NET Web API
The Full Power of ASP.NET Web API
 
Test strategy for web development
Test strategy for web developmentTest strategy for web development
Test strategy for web development
 
Asynchronous JavaScript & XML (AJAX)
Asynchronous JavaScript & XML (AJAX)Asynchronous JavaScript & XML (AJAX)
Asynchronous JavaScript & XML (AJAX)
 
Google Web Toolkits
Google Web ToolkitsGoogle Web Toolkits
Google Web Toolkits
 
Ajax
AjaxAjax
Ajax
 
Servlets intro
Servlets introServlets intro
Servlets intro
 
Rethinking Syncing at AltConf 2019
Rethinking Syncing at AltConf 2019Rethinking Syncing at AltConf 2019
Rethinking Syncing at AltConf 2019
 
How to perform debounce in react
How to perform debounce in reactHow to perform debounce in react
How to perform debounce in react
 
Ajax - a quick introduction
Ajax - a quick introductionAjax - a quick introduction
Ajax - a quick introduction
 
CTS Conference Web 2.0 Tutorial Part 2
CTS Conference Web 2.0 Tutorial Part 2CTS Conference Web 2.0 Tutorial Part 2
CTS Conference Web 2.0 Tutorial Part 2
 
RESTEasy
RESTEasyRESTEasy
RESTEasy
 
HTTP Whiteboard - OSGI Compendium 6.0 - How web apps should have been! - R Auge
HTTP Whiteboard - OSGI Compendium 6.0 - How web apps should have been! - R AugeHTTP Whiteboard - OSGI Compendium 6.0 - How web apps should have been! - R Auge
HTTP Whiteboard - OSGI Compendium 6.0 - How web apps should have been! - R Auge
 
Java web programming
Java web programmingJava web programming
Java web programming
 
Web Component Development Using Servlet & JSP Technologies (EE6) - Chapter 4...
 Web Component Development Using Servlet & JSP Technologies (EE6) - Chapter 4... Web Component Development Using Servlet & JSP Technologies (EE6) - Chapter 4...
Web Component Development Using Servlet & JSP Technologies (EE6) - Chapter 4...
 
Implementing Comet using PHP
Implementing Comet using PHPImplementing Comet using PHP
Implementing Comet using PHP
 
A language for the Internet: Why JavaScript and Node.js is right for Internet...
A language for the Internet: Why JavaScript and Node.js is right for Internet...A language for the Internet: Why JavaScript and Node.js is right for Internet...
A language for the Internet: Why JavaScript and Node.js is right for Internet...
 
Ajax3
Ajax3Ajax3
Ajax3
 

Último

CALL ON ➥8923113531 🔝Call Girls Aminabad Lucknow best Night Fun service
CALL ON ➥8923113531 🔝Call Girls Aminabad Lucknow best Night Fun serviceCALL ON ➥8923113531 🔝Call Girls Aminabad Lucknow best Night Fun service
CALL ON ➥8923113531 🔝Call Girls Aminabad Lucknow best Night Fun serviceanilsa9823
 
Best VIP Call Girls Noida Sector 47 Call Me: 8448380779
Best VIP Call Girls Noida Sector 47 Call Me: 8448380779Best VIP Call Girls Noida Sector 47 Call Me: 8448380779
Best VIP Call Girls Noida Sector 47 Call Me: 8448380779Delhi Call girls
 
Escorts Service Nagavara ☎ 7737669865☎ Book Your One night Stand (Bangalore)
Escorts Service Nagavara ☎ 7737669865☎ Book Your One night Stand (Bangalore)Escorts Service Nagavara ☎ 7737669865☎ Book Your One night Stand (Bangalore)
Escorts Service Nagavara ☎ 7737669865☎ Book Your One night Stand (Bangalore)amitlee9823
 
Editorial design Magazine design project.pdf
Editorial design Magazine design project.pdfEditorial design Magazine design project.pdf
Editorial design Magazine design project.pdftbatkhuu1
 
Verified Trusted Call Girls Adugodi💘 9352852248 Good Looking standard Profil...
Verified Trusted Call Girls Adugodi💘 9352852248  Good Looking standard Profil...Verified Trusted Call Girls Adugodi💘 9352852248  Good Looking standard Profil...
Verified Trusted Call Girls Adugodi💘 9352852248 Good Looking standard Profil...kumaririma588
 
VIP Call Girls Service Mehdipatnam Hyderabad Call +91-8250192130
VIP Call Girls Service Mehdipatnam Hyderabad Call +91-8250192130VIP Call Girls Service Mehdipatnam Hyderabad Call +91-8250192130
VIP Call Girls Service Mehdipatnam Hyderabad Call +91-8250192130Suhani Kapoor
 
Dubai Call Girls Pro Domain O525547819 Call Girls Dubai Doux
Dubai Call Girls Pro Domain O525547819 Call Girls Dubai DouxDubai Call Girls Pro Domain O525547819 Call Girls Dubai Doux
Dubai Call Girls Pro Domain O525547819 Call Girls Dubai Douxkojalkojal131
 
Kala jadu for love marriage | Real amil baba | Famous amil baba | kala jadu n...
Kala jadu for love marriage | Real amil baba | Famous amil baba | kala jadu n...Kala jadu for love marriage | Real amil baba | Famous amil baba | kala jadu n...
Kala jadu for love marriage | Real amil baba | Famous amil baba | kala jadu n...babafaisel
 
VIP Call Girls Service Kukatpally Hyderabad Call +91-8250192130
VIP Call Girls Service Kukatpally Hyderabad Call +91-8250192130VIP Call Girls Service Kukatpally Hyderabad Call +91-8250192130
VIP Call Girls Service Kukatpally Hyderabad Call +91-8250192130Suhani Kapoor
 
VVIP CALL GIRLS Lucknow 💓 Lucknow < Renuka Sharma > 7877925207 Escorts Service
VVIP CALL GIRLS Lucknow 💓 Lucknow < Renuka Sharma > 7877925207 Escorts ServiceVVIP CALL GIRLS Lucknow 💓 Lucknow < Renuka Sharma > 7877925207 Escorts Service
VVIP CALL GIRLS Lucknow 💓 Lucknow < Renuka Sharma > 7877925207 Escorts Servicearoranaina404
 
VVIP Pune Call Girls Hadapsar (7001035870) Pune Escorts Nearby with Complete ...
VVIP Pune Call Girls Hadapsar (7001035870) Pune Escorts Nearby with Complete ...VVIP Pune Call Girls Hadapsar (7001035870) Pune Escorts Nearby with Complete ...
VVIP Pune Call Girls Hadapsar (7001035870) Pune Escorts Nearby with Complete ...Call Girls in Nagpur High Profile
 
Government polytechnic college-1.pptxabcd
Government polytechnic college-1.pptxabcdGovernment polytechnic college-1.pptxabcd
Government polytechnic college-1.pptxabcdshivubhavv
 
Kurla Call Girls Pooja Nehwal📞 9892124323 ✅ Vashi Call Service Available Nea...
Kurla Call Girls Pooja Nehwal📞 9892124323 ✅  Vashi Call Service Available Nea...Kurla Call Girls Pooja Nehwal📞 9892124323 ✅  Vashi Call Service Available Nea...
Kurla Call Girls Pooja Nehwal📞 9892124323 ✅ Vashi Call Service Available Nea...Pooja Nehwal
 
Pooja 9892124323, Call girls Services and Mumbai Escort Service Near Hotel Hy...
Pooja 9892124323, Call girls Services and Mumbai Escort Service Near Hotel Hy...Pooja 9892124323, Call girls Services and Mumbai Escort Service Near Hotel Hy...
Pooja 9892124323, Call girls Services and Mumbai Escort Service Near Hotel Hy...Pooja Nehwal
 
Tapestry Clothing Brands: Collapsing the Funnel
Tapestry Clothing Brands: Collapsing the FunnelTapestry Clothing Brands: Collapsing the Funnel
Tapestry Clothing Brands: Collapsing the Funneljen_giacalone
 
The history of music videos a level presentation
The history of music videos a level presentationThe history of music videos a level presentation
The history of music videos a level presentationamedia6
 

Último (20)

CALL ON ➥8923113531 🔝Call Girls Aminabad Lucknow best Night Fun service
CALL ON ➥8923113531 🔝Call Girls Aminabad Lucknow best Night Fun serviceCALL ON ➥8923113531 🔝Call Girls Aminabad Lucknow best Night Fun service
CALL ON ➥8923113531 🔝Call Girls Aminabad Lucknow best Night Fun service
 
Best VIP Call Girls Noida Sector 47 Call Me: 8448380779
Best VIP Call Girls Noida Sector 47 Call Me: 8448380779Best VIP Call Girls Noida Sector 47 Call Me: 8448380779
Best VIP Call Girls Noida Sector 47 Call Me: 8448380779
 
Escorts Service Nagavara ☎ 7737669865☎ Book Your One night Stand (Bangalore)
Escorts Service Nagavara ☎ 7737669865☎ Book Your One night Stand (Bangalore)Escorts Service Nagavara ☎ 7737669865☎ Book Your One night Stand (Bangalore)
Escorts Service Nagavara ☎ 7737669865☎ Book Your One night Stand (Bangalore)
 
young call girls in Vivek Vihar🔝 9953056974 🔝 Delhi escort Service
young call girls in Vivek Vihar🔝 9953056974 🔝 Delhi escort Serviceyoung call girls in Vivek Vihar🔝 9953056974 🔝 Delhi escort Service
young call girls in Vivek Vihar🔝 9953056974 🔝 Delhi escort Service
 
Editorial design Magazine design project.pdf
Editorial design Magazine design project.pdfEditorial design Magazine design project.pdf
Editorial design Magazine design project.pdf
 
Verified Trusted Call Girls Adugodi💘 9352852248 Good Looking standard Profil...
Verified Trusted Call Girls Adugodi💘 9352852248  Good Looking standard Profil...Verified Trusted Call Girls Adugodi💘 9352852248  Good Looking standard Profil...
Verified Trusted Call Girls Adugodi💘 9352852248 Good Looking standard Profil...
 
VIP Call Girls Service Mehdipatnam Hyderabad Call +91-8250192130
VIP Call Girls Service Mehdipatnam Hyderabad Call +91-8250192130VIP Call Girls Service Mehdipatnam Hyderabad Call +91-8250192130
VIP Call Girls Service Mehdipatnam Hyderabad Call +91-8250192130
 
Dubai Call Girls Pro Domain O525547819 Call Girls Dubai Doux
Dubai Call Girls Pro Domain O525547819 Call Girls Dubai DouxDubai Call Girls Pro Domain O525547819 Call Girls Dubai Doux
Dubai Call Girls Pro Domain O525547819 Call Girls Dubai Doux
 
Kala jadu for love marriage | Real amil baba | Famous amil baba | kala jadu n...
Kala jadu for love marriage | Real amil baba | Famous amil baba | kala jadu n...Kala jadu for love marriage | Real amil baba | Famous amil baba | kala jadu n...
Kala jadu for love marriage | Real amil baba | Famous amil baba | kala jadu n...
 
B. Smith. (Architectural Portfolio.).pdf
B. Smith. (Architectural Portfolio.).pdfB. Smith. (Architectural Portfolio.).pdf
B. Smith. (Architectural Portfolio.).pdf
 
꧁❤ Hauz Khas Call Girls Service Hauz Khas Delhi ❤꧂ 9999965857 ☎️ Hard And Sex...
꧁❤ Hauz Khas Call Girls Service Hauz Khas Delhi ❤꧂ 9999965857 ☎️ Hard And Sex...꧁❤ Hauz Khas Call Girls Service Hauz Khas Delhi ❤꧂ 9999965857 ☎️ Hard And Sex...
꧁❤ Hauz Khas Call Girls Service Hauz Khas Delhi ❤꧂ 9999965857 ☎️ Hard And Sex...
 
VIP Call Girls Service Kukatpally Hyderabad Call +91-8250192130
VIP Call Girls Service Kukatpally Hyderabad Call +91-8250192130VIP Call Girls Service Kukatpally Hyderabad Call +91-8250192130
VIP Call Girls Service Kukatpally Hyderabad Call +91-8250192130
 
VVIP CALL GIRLS Lucknow 💓 Lucknow < Renuka Sharma > 7877925207 Escorts Service
VVIP CALL GIRLS Lucknow 💓 Lucknow < Renuka Sharma > 7877925207 Escorts ServiceVVIP CALL GIRLS Lucknow 💓 Lucknow < Renuka Sharma > 7877925207 Escorts Service
VVIP CALL GIRLS Lucknow 💓 Lucknow < Renuka Sharma > 7877925207 Escorts Service
 
VVIP Pune Call Girls Hadapsar (7001035870) Pune Escorts Nearby with Complete ...
VVIP Pune Call Girls Hadapsar (7001035870) Pune Escorts Nearby with Complete ...VVIP Pune Call Girls Hadapsar (7001035870) Pune Escorts Nearby with Complete ...
VVIP Pune Call Girls Hadapsar (7001035870) Pune Escorts Nearby with Complete ...
 
Government polytechnic college-1.pptxabcd
Government polytechnic college-1.pptxabcdGovernment polytechnic college-1.pptxabcd
Government polytechnic college-1.pptxabcd
 
Kurla Call Girls Pooja Nehwal📞 9892124323 ✅ Vashi Call Service Available Nea...
Kurla Call Girls Pooja Nehwal📞 9892124323 ✅  Vashi Call Service Available Nea...Kurla Call Girls Pooja Nehwal📞 9892124323 ✅  Vashi Call Service Available Nea...
Kurla Call Girls Pooja Nehwal📞 9892124323 ✅ Vashi Call Service Available Nea...
 
Call Girls Service Mukherjee Nagar @9999965857 Delhi 🫦 No Advance VVIP 🍎 SER...
Call Girls Service Mukherjee Nagar @9999965857 Delhi 🫦 No Advance  VVIP 🍎 SER...Call Girls Service Mukherjee Nagar @9999965857 Delhi 🫦 No Advance  VVIP 🍎 SER...
Call Girls Service Mukherjee Nagar @9999965857 Delhi 🫦 No Advance VVIP 🍎 SER...
 
Pooja 9892124323, Call girls Services and Mumbai Escort Service Near Hotel Hy...
Pooja 9892124323, Call girls Services and Mumbai Escort Service Near Hotel Hy...Pooja 9892124323, Call girls Services and Mumbai Escort Service Near Hotel Hy...
Pooja 9892124323, Call girls Services and Mumbai Escort Service Near Hotel Hy...
 
Tapestry Clothing Brands: Collapsing the Funnel
Tapestry Clothing Brands: Collapsing the FunnelTapestry Clothing Brands: Collapsing the Funnel
Tapestry Clothing Brands: Collapsing the Funnel
 
The history of music videos a level presentation
The history of music videos a level presentationThe history of music videos a level presentation
The history of music videos a level presentation
 

Android dev 3

  • 1. Intro to Android Development 3 Accessibility Capstone Nov 29, 2011
  • 2. Outline • Web Services • XML vs. JSON • Your Own Web Service
  • 3. Hello, Android The key to the capstone… (sort of)
  • 4. Using Web Services HTTP Request HTTP Response
  • 5. Using Web Services HTTP Request HTTP Response
  • 6. Using Web Services HTTP Request HTTP Response webserver some program
  • 7. Why use a web service?
  • 12. An HTTP Response • Response code 2xx = success!  4xx = client error 5xx = server error
  • 13. An HTTP Response • Response code 2xx = success!  4xx = client error 5xx = server error • Response body (XML, JSON) <geonames> <entry> <lang>en</lang> <title>London</title> <summary> London (; and largest urban area of England and the United Kingdom. At its core, the ancient City of London, to which the name historically belongs, still retains its limited mediaeval boundaries; but since at least the 19th century the name "London" has also referred to the whole metropolis which has developed around
  • 14. XML and JSON • Parsers – XML: Different traversals include SAX, DOM, etc. – JSON: Look at JSONObject/JSONArray classes • Overviews – http://www.w3schools.com/json/ – http://www.w3schools.com/xml/ • Recommend using JSON: small, easy to parse, fast
  • 16. JSON { "employees": [ { "firstname":"John" , "lastname":"Doe" }, { "firstname":"Anna" , "lastname":"Smith" }, { "firstname":"Peter" , “lastname":"Jones" } ] }
  • 17. JSON • Name/Value Pairs: “name” : “value” – "firstname":"John" • JSON Objects: , … - – { "firstname":"John" , "lastname":"Doe" } • JSON Arrays: * …, …, … + [ { "firstname":"John" , "lastname":"Doe" }, { "firstname":"Anna" , "lastname":"Smith" }, … ]
  • 18. How to Use a Webservice • Find a webservice or write your own example: www.geonames.org • Construct the URL add parameters, extra headers (if needed • Execute the request asynchronously • Check the response code 200 = success, 4xx = client error, 5xx = server error • Parse the response body
  • 19. Construct the URL final static String PLACE_NAME = "Seattle"; final static String URL = “http://ws.geonames.org/” + “wikipediaSearch?q=" + PLACE_NAME + "&maxRows=4";
  • 20. Execute the Request public String callWebService(){ HttpClient httpclient = new DefaultHttpClient(); HttpGet request = new HttpGet(URL); String result = ""; ResponseHandler<String> handler = new BasicResponseHandler(); try { result = httpclient.execute(request, handler); } catch (ClientProtocolException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } httpclient.getConnectionManager().shutdown(); return result; }
  • 21. Execute the Request public String callWebService(){ HttpClient httpclient = new DefaultHttpClient(); HttpGet request = new HttpGet(URL); String result = ""; ResponseHandler<String> handler = new BasicResponseHandler(); try { result = httpclient.execute(request, handler); } catch (ClientProtocolException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } httpclient.getConnectionManager().shutdown(); return result; } the client will open a connection and executes the request
  • 22. Execute the Request public String callWebService(){ HttpClient httpclient = new DefaultHttpClient(); HttpGet request = new HttpGet(URL); String result = ""; ResponseHandler<String> handler = new BasicResponseHandler(); try { result = httpclient.execute(request, handler); } catch (ClientProtocolException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } httpclient.getConnectionManager().shutdown(); return result; } request object contains URL
  • 23. Execute the Request public String callWebService(){ HttpClient httpclient = new DefaultHttpClient(); HttpGet request = new HttpGet(URL); String result = ""; ResponseHandler<String> handler = new BasicResponseHandler(); try { result = httpclient.execute(request, handler); } catch (ClientProtocolException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } httpclient.getConnectionManager().shutdown(); return result; } this kind of response handler will return the response body as a string if the request was successful
  • 24. Execute the Request public String callWebService(){ HttpClient httpclient = new DefaultHttpClient(); HttpGet request = new HttpGet(URL); String result = ""; ResponseHandler<String> handler = new BasicResponseHandler(); try { result = httpclient.execute(request, handler); } catch (ClientProtocolException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } httpclient.getConnectionManager().shutdown(); return result; } executes the request and processes the response using the handler
  • 25. Execute the Request public String callWebService(){ HttpClient httpclient = new DefaultHttpClient(); HttpGet request = new HttpGet(URL); String result = ""; ResponseHandler<String> handler = new BasicResponseHandler(); try { result = httpclient.execute(request, handler); } catch (ClientProtocolException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } httpclient.getConnectionManager().shutdown(); return result; } generated by the handler
  • 26. Calling on callWebService() and Displaying the Results public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); TextView tv = (TextView) findViewById(R.id.resultTV); String result = callWebService(); tv.setText(result); }
  • 27. What’s wrong with the example?
  • 28. What’s wrong with the example? • result = httpclient.execute(request, handler); blocks and waits for entire page to download! • Solution: threads – You may have to use another thread in your application! – java.util.concurrent package – Good example in Hello, Android (web services chapter) – Keeping it all simple is key, then program away
  • 29. Your Own Web Service • May need if… – You need additional processing power – You want to tie phone app into a web product – Etc… • If you create your own web service… – Server Side Scripting (PHP, Ruby on Rails, etc.) – Web server (abstract.cs, etc.)
  • 30. Your Own Web Service • Very Basic PHP Overview: 1. Create .php page (http://foo.com/service.php) 2. Use $_GET*‘param’+ (http://foo.com/service.php?param=helloworld 3. Do stuff with the parameters ($bar = $_GET*‘param’+ ) 4. Format output into XML or JSON or whatever you need (echo $bar) • Phone app will visit php page and get its result
  • 31. Other Topics • GPS and Sensors – LocationManager • SQL Database – SQLiteDatabase • Camera • Multitouch
  • 32. Exercise Develop an application that uses a web service that is accessible to a blind person. For extra brownie points: use the GPS! -Use TTS to make the application accessible. -Find a web service (you can start from Geonames) -Find and use a Java XML parser to parse the response body (you can try SAX) Note: many web services use JSON, not XML.